arm-linux-gcc-4.4.3交叉編譯google的protobuf。以及使用方法

來源:互聯網
上載者:User

source : http://hi.baidu.com/guccang/item/9205cbe25c3a1c03570f1dfb

一:本機環境:Ubuntu64位作業系統

uname -a 查詢

作業系統:Ubuntu 64位作業系統

交叉編譯器:arm-linux-gcc-4.4.3

google protobuf:protobuf-2.4.1

結果,make 時,提示can not find arm-linux-g++

二:本機環境: red hat 32位作業系統

uname -a 查詢

作業系統:Linux suowenair 2.6.32-131.0.15.el6.i686 #1 SMP Tue May 10 15:42:28 EDT 2011 i686 i686 i386 GNU/Linux

交叉編譯器:arm-linux-gcc-4.4.3

google protobuf: protobuf-2.4.1:

步驟:

第一步:部署protoc.exe檔案。

./configure 

sudo make

sudo make check

sudo make install

make distclean

make distclean清理產生的Makefile檔案,為第二次配置Makefile做準備

make check不會出任何錯誤提示

第二步:交叉編譯

配置makefile檔案.

1:./configure --build=i686_pc_linux_gnu --host=arm-linux --with-protoc=protoc --prefix=path_of_arm_linux_lib

--build表示本機環境,如果不清楚,在第一步,./configure時產生makefile時,查看列印資訊,或插卡第一步產生的makefile

--host表示編譯庫的啟動並執行環境,我的是arm架構cpu上運行,所以使用arm-linux,而產生的makefile中--host選項是arm-unknown-linux-gnu

--with-protoc=protoc,此選項的設定,是應為README.txt中所屬,交叉編譯需要增加此項,如果沒有第一步得到部署protoc.exe,會出現錯誤

錯誤提示為:protoc找不到。

--prefix=path_of_arm_linux_lib,及設定為交叉編譯工具arm-linux-gcc-4.4.3的lib目錄的上層目錄,--prefix設定的路徑,就是make install時,

protobuf的Include,lib目錄的拷貝目錄。目的在編譯時間為使用google protobuf標準話的庫應用方式(`pkg-config --cflags --libs protobuf`)。

如上配置好configure後,產生Makefile檔案,確認CC/CCXX等是否等於arm-linux版本的命令。

我的是 CC=arm-linux-gcc  CCXX=arm-linux-g++

2:sudo make

如果未配置--with-protoc=protoc會出錯。

如果未執行第一步會出錯。提示找不到protoc

其他錯誤未知。

3:sudo make check

此步驟全部失敗,我的提示監測了5個,但5個全部失敗。不知道為什嗎?

但對於arm平台使用libprotobuf.a庫沒有問題。其他庫,為驗證。

4:sudo make install 

無錯誤

三:使用庫

查看,protobuf的例子。example檔案夾,下的Makefile,我們來分析一下:Makfile片段

add_person_cpp: add_person.cc protoc_middleman

        pkg-config --cflags protobuf  # fails if protobuf is not installed

        c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`

1:使用了 pkg-config --cflags protobuf  # fails if protobuf is not installed

來檢查是否安裝了protobuf

2:使用c++來編譯,沒有使用g++,

3:使用`pkg-config --cflags --libs protobuf`來表示載入libprotobuf.a庫。

      而未使用顯示配置:-L/path0flib -lprotobuf

注意`pkg-config --cflags --libs protobuf`使用 數字1左邊那個按鍵,而非單引號。

4:那我使用arm-linux編譯時間,同樣使用如上格式,注意三點:

pkg-config --cflags protobuf  # fails if protobuf is not installed以防萬一

`pkg-config --cflags --libs protobuf`這種形式來載入protobuf的庫

arm-linux-c++來編譯C++工程。

5:為何要注意上述三點:筆者在使用時遇到了問題。

如使用arm-linux-g++來編譯工程但總是提示找不到libprotobuf.a這個庫。

按道理來說找不到庫原因:有兩個

其一是:庫所在目錄為包含到搜尋目錄。

其二是:庫的版本不對,如arm-linux編譯器,串連非arm-linux編譯的庫。

但兩個我都滿足了。可任然無法找到libprotobuf.a庫檔案。

而是用arm-linux-c++就可以。

6:此文,僅為...希望和我遇到同樣問題的同學不在糾結了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.