Use mips-linux-gnu-gcc to cross-compile OpenCV libraries under Ubuntu 14.04 LTS

Many thanks
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. Cross-compilation of zlib:


./configure --prefix=$OPENCV_DEPEND
1 After
1
, modify the Makefile as follows: 


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. Cross compilation of 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


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


4. Cross compilation of yasm:


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




5. Cross compilation of libx264:


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




6. Cross-compilation of libxvid:


After entering the libxvid directory, enter its subdirectory:


cd ./build/generic


and then enter the command:


./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. Cross compilation of 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
Note: When installing according to this process, download ffmpeg version 2.8, do not download the latest ffmpeg version 3.3! Otherwise, a make error may be displayed when I compile OpenCV to 21%;




Makefile options CFLAGS, LDFLAGS, LIBS
CFLAGS represent options for C compiler, and
CXXFLAGS represent options for C++ compiler.
These two variables actually cover the two steps of compilation and assembly.


CFLAGS: Specify the path of the header file (.h file), such as: CFLAGS=-I/usr/include -I/path/include. Similarly, when installing a package, an include directory will be created in the installation path. When there is a problem during the installation process, try


to add the include directory of the previously installed package to this variable.


LDFLAGS: Some optimization parameters used by compilers such as gcc, and the location of library files can also be specified in it. Usage: LDFLAGS=-L/usr/lib -L/path/to/your/lib. Every installation of a package will almost certainly create


a directory. If a package is clearly installed, and another package is installed, it says that it cannot be found, you can try it in LDFALGS added to the lib path of that package.


LIBS: Tell the linker which library files to link, such as LIBS=-lpthread-liconv


Simply put, LDFLAGS tells the linker where to look for library files, and LIBS tells the linker which library files to link. However, these two parameters will be added at the link stage when used, so even if you exchange the values ​​of these two, there is no problem.


Sometimes LDFLAGS specifies -L, although the linker can find the library for linking, but the runtime linker cannot find the library. If the path of the software runtime library file is to be expanded, then we need to add these two libraries. Give "-Wl,R":


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


If you set the environment variable export LDFLAGS="-L/var/xxx/lib -L/opt/mysql/lib -Wl,R/var/xxx/lib -Wl,R/opt/mysql/lib before executing ./configure " , note that there can be no


spaces , and quotation marks must be added (the usage of the shell). Then after executing configure, the Makefile will set this option, and this parameter will be present when linking, and the library file search path of the compiled executable program will be expanded.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325859647&siteId=291194637