Building / Cross Compiling OpenCV for Linux ARM
This article outlines the steps necessary for building OpenCV for a Linux ARM target. OpenCV is an open-source, cross-platform computer vision and machine vision library.
I cross compiled OpenCV for a Xilinx Zinq ARM system yesterday by more-or-less following the steps outlined in the above document – I had to change a few things to get the build to work. I am documenting the exact steps that I took in case anybody is having trouble (probably future me!).
I started with a fairly clean Ubuntu install on a virtual machine (it already had git installed) , first I installed some build tools, feel free to skip any that you already have:
sudo apt-get install build-essential sudo apt-get install cmake
Then I installed the GNU ARM tool-chain:
sudo apt-get install gcc-arm-linux-gnueabi sudo apt-get install g++-arm-linux-gnueabi
This installed version 4.7 of the compilers while the build process calls for version 4.6, to get around this I modified the cmake platform file slightly, see below.
Create a build directory, cd into it and get the OpenCV source from github:
mkdir opencv_build cd opencv_build git clone https://github.com/Itseez/opencv.git
To fix the version problem I modified the compiler version in the platform file (this may not be the most correct way to do this but it worked for me!):
I edited this file:
./opencv/platforms/linux/arm-gnueabi.toolchain.cmake
I changed the GCC_COMPILER_VERSION variable’s value from 4.6 to 4.7 to match my installed compiler. I had to edit the file as I wasn’t able to override these variables from the command line.
Now create a sub-directory called build and cd into it:
mkdir build cd build
And configure the build:
cmake -DSOFTFP=ON -DCMAKE_TOOLCHAIN_FILE=../opencv/platforms/linux/arm-gnueabi.toolchain.cmake ../opencv
This should complete without errors if you have the compiler that it is looking for installed etc.
Now run ‘make’ and ‘make install’:
make make install
Make will take a few minutes to run, make install should copy the output files to a subdirectory called ‘install’.
All being well you should now have all the include and lib files that you need to build an OpenCV app for your ARM device.
Hi,
Thanks for the tutorial. I had problems with the following cammands:
sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install g++-arm-linux-gnueabi
I got the following error
E: Unable to locate package gcc-arm-linux-gnueabi
What am I doing wron (I am on a debian linux system on virtual box hosted bby Win 7 64 bit Intel
Regards
Rob
Hello, Rob.
You should try to update your package library running “apt-get update”.
Also, you should check the internet connection in your virtual box running OS, in case the above does not work.
Hi,
thanks for the tutorial. It works fine on my Ubuntu 12.04 LTS.
How can I compile a .cpp file for ARM target?
So far I’ve always done it this way:
g++ test.c `pkg-config –libs –cflags opencv`
Best regards,
Michael
Hello, great tutorial
but i am facing an error after the make command which are
make[2]: *** [3rdparty/lib/libzlib.a] Error 2
make[1]: *** [3rdparty/zlib/CMakeFiles/zlib.dir/all] Error 2
make: *** [all] Error 2
please help.
Hey,
i have the some problems like Gelila :-/ some could you please help ?
Hello, I ‘m getting the same error as mentioned above, can anyone tell me what can be done??
Please reply soon
Akash