Ubuntu 14.04 LTS下使用mips-linux-gnu-gcc交叉編譯OpenCV所需庫__linux

來源:互聯網
上載者:User
非常感謝
http://blog.h5min.cn/ajianyingxiaoqinghan/article/details/70194392
http://blog.h5min.cn/zdyueguanyun/article/details/51322295
http://blog.csdn.net/tgww88/article/details/51393570


1、zlib的交叉編譯:


./configure --prefix=$OPENCV_DEPEND
1
1
之後,對Makefile檔案進行修改,修改內容如下: 


CC=mips-linux-gnu-gcc 
LDSHARED=mips-linux-gnu-gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map
CPP=mips-linux-gnu-gcc -E




AR=mips-linux-gnu-ar
ARFLAGS=rc
RANLIB=mips-linux-gnu-gcc-ranlib 






2、libjpeg的交叉編譯:


./configure --host=mips-linux-gnu --prefix=$OPENCV_DEPEND --enable-shared --enable-static
make
make install




3、libpng的交叉編譯:


./configure --host=mips-linux-gnu --prefix=$OPENCV_DEPEND --enable-shared --enable-static
出錯
configure: error: zlib not installed


export LDFLAGS=-L$ROOTFS_DIR/usr/local/mips/opencv-depend/lib
export CFLAGS=-I$ROOTFS_DIR/usr/local/mips/opencv-depend/include
./configure --host=mips-linux-gnu --prefix=$OPENCV_DEPEND --enable-shared --enable-static
make
仍然出錯,提示
pnglibconf.c:33:19: fatal error: zlib.h: No such file or directory


參考http://code-by.org/viewtopic.php?f=55&t=169
vim Makefile +256改為
DEFAULT_INCLUDES = -I. -I/usr/local/mips/opencv-depend/include
make
make install


4、yasm的交叉編譯:


CC=mips-linux-gnu-gcc ./configure --enable-shared --host=mips-linux-gnu --disable-asm --prefix=$OPENCV_DEPEND
make
make install




5、libx264的交叉編譯:


CC=mips-linux-gnu-gcc ./configure --enable-shared --host=mips-linux-gnu --disable-asm --prefix=$OPENCV_DEPEND
make
make install




6、libxvid的交叉編譯:


進入libxvid的目錄後,再行進入其子目錄中:


cd ./build/generic


然後輸入命令:


./configure --prefix=$OPENCV_DEPEND --host=arm-linux --disable-assembly
make
make install




7、ffmpeg的交叉編譯:


./configure --prefix=$OPENCV_DEPEND --enable-shared --disable-static --enable-gpl --enable-cross-compile --arch=mips --disable-stripping --target-os=linux --


enable-libx264 --enable-libxvid --cc=mips-linux-gnu-gcc --enable-swscale --extra-ldflags=-L$OPENCV_DEPEND/lib --extra-cflags=-l$OPENCV_DEPEND/include


./configure --prefix=$OPENCV_DEPEND --enable-shared --disable-static --enable-gpl --enable-cross-compile --arch=mips --disable-stripping --target-os=linux --


enable-libx264 --enable-libxvid --cc=mips-linux-gnu-gcc --enable-swscale --extra-ldflags=-L$OPENCV_DEPEND/lib --extra-cflags=-I$OPENCV_DEPEND/include


7,  ffmpeg 的交叉編譯:


 ./configure --cross-prefix=mips-linux-gnu- --enable-cross-compile --target-os=linux --cc=mips-linux-gnu-gcc --arch=mips --prefix=$OPENCV_DEPEND --enable-shared 


--disable-static --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-pthreads --disable-armv5te --


disable-armv6 --disable-armv6t2 --disable-yasm --disable-stripping --enable-libx264 --extra-ldflags=-L$OPENCV_DEPEND/lib --extra-cflags=-I$OPENCV_DEPEND/include 


--extra-libs=-ldl


make


make install
註:按照該流程安裝時,下載ffmpeg 2.8版本,不要下載最新的ffmpeg 3.3版本。否則可能會像筆者編譯OpenCV至21%時,顯示make錯誤;




Makefile選項CFLAGS,LDFLAGS,LIBS
CFLAGS 表示用於 C 編譯器的選項,
CXXFLAGS 表示用於 C++ 編譯器的選項。
這兩個變數實際上涵蓋了編譯和彙編兩個步驟。


CFLAGS: 指定標頭檔(.h檔案)的路徑,如:CFLAGS=-I/usr/include -I/path/include。同樣地,安裝一個包時會在安裝路徑下建立一個include目錄,當安裝過程中出現問題時,試


著把以前安裝的包的include目錄加入到該變數中來。


LDFLAGS:gcc 等編譯器會用到的一些最佳化參數,也可以在裡面指定庫檔案的位置。用法:LDFLAGS=-L/usr/lib -L/path/to/your/lib。每安裝一個包都幾乎一定的會在安裝目錄裡建立


一個lib目錄。如果明明安裝了某個包,而安裝另一個包時,它愣是說找不到,可以抒那個包的lib路徑加入的LDFALGS中試一下。


LIBS:告訴連結器要連結哪些庫檔案,如LIBS = -lpthread -liconv


簡單地說,LDFLAGS是告訴連結器從哪裡尋找庫檔案,而LIBS是告訴連結器要連結哪些庫檔案。不過使用時連結階段這兩個參數都會加上,所以你即使將這兩個的值互換,也沒有問題。


有時候LDFLAGS指定-L雖然能讓連結器找到庫進行連結,但是運行時連結器卻找不到這個庫,如果要讓軟體執行階段程式庫檔案的路徑也得到擴充,那麼我們需要增加這兩個庫給"-Wl,R":


LDFLAGS = -L/var/xxx/lib -L/opt/mysql/lib -Wl,R/var/xxx/lib -Wl,R/opt/mysql/lib


如果在執行./configure以前設定環境變數export LDFLAGS="-L/var/xxx/lib -L/opt/mysql/lib -Wl,R/var/xxx/lib -Wl,R/opt/mysql/lib" ,注意設定環境變數等號兩邊不可以有空


格,而且要加上引號(shell的用法)。那麼執行configure以後,Makefile將會設定這個選項,連結時會有這個參數,編譯出來的可執行程式的庫檔案搜尋路徑就得到擴充了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.