2015年8月25日 星期二

如何透過 adb command 取得Android CPU 資訊

        將手機連上電腦後在 console Mode 下執行 "adb shell cat /proc/cpuinfo" 即可得到如下訊息,如果手機是四核心則會出現四次一樣的訊息。

~$ adb shell cat /proc/cpuinfo

processor : 0
vendor_id : GenuineIntel
cpu family : 6
model  : 90
model name : Intel(R) Atom(TM) CPU  Z3560  @ 1.00GHz
stepping : 0
microcode : 0x34
cpu MHz  : 500.000
cache size : 1024 KB
physical id : 0
siblings : 4
core id  : 0
cpu cores : 4
apicid  : 0
initial apicid : 0
fpu  : yes
fpu_exception : yes
cpuid level : 11
wp  : yes
flags  : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch ida arat epb dtherm tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms

[參考鏈結]

2015年5月26日 星期二

[Error] Invalid conversion from 'int' to 'main(int, char**)::fruit_tea' [-fpermissive]


當你嘗試編譯將 int 數值指定給 enum 型態的變數時,會出現編譯錯誤訊息如下:
Invalid conversion from 'int' to 'main(int, char**)::fruit_tea' [-fpermissive]

範例程式如下:
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) 
{
 enum fruit_tea { apple, banana, orange } taste;
 taste = 10;
 std::cout << taste << std::endl;
 return 0;
}

解決方法就是將 fpermissive flag 加入到編譯的選項中,下面的圖示是使用 OrWell Dev-C++ IDE,設定方法步驟:點選 project 右鍵 >> Project Options... >> Parameters 在 C++ compiler中填入 -fpermissive 即可。重新編譯程式時,原本錯誤的地方就變成是 Warning 了。


下面有關 fpermissive flag 的解釋擷取至 3.5 Options Controlling C++ Dialect 。主要是讓原本編譯器將某些不合適的 code 判斷為錯誤的訊息改成為警告訊息,以便讓程式可以編譯成功。

-fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive will allow some nonconforming code to compile. 

上面的例子,想要將整數值指定給列舉型態變數;因為指定的整數值未必在列舉型態的範圍內,所以C++ 禁止將 整數值指定給 列舉型態變數,但可以將列舉型態變數值指定給整數型態變數,因為列舉型態也是一種整數型態。

基本上不建議使用 fpermissive flag 來解此類的問題,如上面所說 整數值未必在 列舉型態的範圍中,允許指定整數值給列舉型態可能會造成不必要的麻煩。


[相關鏈結]

2015年5月21日 星期四

Error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format

最近把一個 Third Party Lib include 到專案內;使用VS 2010 編譯時卻出現下列問題,在 Ubuntu下編譯卻不會這樣的問題發生。比較快的方式是將所有的 Third Party 的 Source code 修正成 Windows 或者 UNIX 的檔案格式。但這樣不是很理想,我們不應該修改 Third Party 的Source code 除非必要。這樣以後要 Upgrade 才不會遇到太多問題。
 
error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format

要解決這個問題又不改到 Third Party Source Code 的方法就是直接把那個 C4335 關閉即可,下面是如何關閉的圖示:


  • 點選專案 > 右鍵 > 選擇 Properties
  • Configuration Properties > C/C++ > Advanced > Disable Specific Warnings 填入 4335 即可。



2015年1月21日 星期三

讓 Code::Blocks IDE 輸出中繼檔案

     編譯 C/C++ 檔案時你可以設定 flag 讓編譯器產邊中繼檔案,一般  Code::Blocks 未做任何設定時只會輸出 .o 檔,如果你編譯器是使用 GCC,那麼你可以設定編譯器的 -save-temps 來輸出 .ii 與 .s 檔。.ii 就是前置處理器完後的 source 檔,.s 就是 asm 檔。如果使用 -save-temps 則輸出的檔案與你的 cpp 檔案放在同一個目錄下,而設定為 -save-temps=obj 則會輸出到 obj 的目錄下。下面是 Code::Blocks 設定畫面:




2015年1月8日 星期四

如何用 Code::Blocks IDE 編譯 C++11 程式

      假設你在 Code::Blocks 中,專案使用的是 g++ 編譯器來編譯,你可以點選專案右鍵後選擇 "Build options..." 然後將 -std=c++11 選項勾選即可編譯 c++11 feature 的程式了。
設定畫面如下:



測試範例程式如下:(來源 C++11 Wiki Range-based_for_loop)

#include <iostream>

using namespace std;

int main()
{
    //Range-based for loop
    int my_array[5] = {1, 2, 3, 4, 5};
    for (auto &x : my_array) {
        cout << x << " ";
    }
    cout << endl;
    return 0;
}

       注意:專案的編譯器設定會被 全域的編譯器設定所覆蓋,假設你在專案中設定 -std=c++11,但在全域編譯器中設定了 -std=c++98,則編譯最後是使用 c++98來編譯程式。 檢查 Build log 你會發現,編譯的指令為 mingw32-g++.exe -Wall -fexceptions -std=c++11 -g -std=c++98 ...。

Code::Blocks IDE 如何設定 Boost C++ libraries

        先到 Boost C++ libraries 網站下載 Boost libs 壓縮檔案,然後將其解壓縮,解壓縮後的目錄結構如下:

     然後開啟 Code::Blocks IDE,執行 Settings > Compiler... 項目,切換到 Search directories 也面分別設定 Compiler 與 Linker 的路徑即可,設定畫面如下:
  • 設定 Compiler 搜尋路徑

  • 設定 Linker 搜尋路徑


設定好後,可以透過下列的範例程式來驗證是否設定正確:

#include <iostream>
using std::cout;
using std::endl;

#include  <boost\shared_ptr.hpp>
using boost::shared_ptr;

int main()
{
    shared_ptr<int>sp(new int(5));
    cout << *sp << endl;
    return 0;
}

2015年1月3日 星期六

新增修改 Code::Blocks 的 Colour themes

    安裝完後的 Code::Blocks IDE 其 Colour Theme 只有一個 default可以選擇,如果想要新增、更換 Colour Theme 請依據下列幾個步驟來完成更新替換Colour Theme。
  1. 關閉 Code::Blocks IDE。

  2. 到 Syntax highlighting custom colour themes 將 wiki 網頁所 po 的 xml 文字訊息拷貝下來,另存 *.conf 檔案 (i.e: colour_themes.conf )。

  3. 執行 cb_share_config.exe 程式 (該程式可在 Code::Blocks IDE 安裝路徑下找到 ) 。Win7/Win8 可以透過下列方式找到該程式。

  4. 當開啟 CB Share Config 程式後,左邊選擇你所另存的 *.conf 檔,右邊選擇 Code::Blocks 的 default.conf 檔案 (可在 C:\Users\[你登入的帳號]\AppData\Roaming\CodeBlocks 下找到);之後在左邊勾選你想要匯入的 Colour Theme 項目,按 Transfer 後會跳出幾個視窗,按確定即可;最後要按 Save 才會將設定檔寫入到 default.conf 檔案中。可參考下列圖示:

  5. 開啟 Code::Blocks IDE 點選 Settings->Editor... 選擇 Syntax highlighting後,如果一切順利你可以在 Colour Theme 中發現我們剛剛所新增的 Themes,選擇其一來更換你的 Theme。

  6. 如果你選擇黑色背景的 Theme 請記得設定 Caret,因為預設的顏色是黑色的,如果沒更換會無法得知目前停留或編輯到哪一行。設定方式點選 Settings->Editor... 選擇 Margins and caret 後,便可設定 Caret 的顏色與寬度大小 (建議設定 2)。可參考下列圖示:
     


[參考資料]