Cross-compiling opencv2.31 and porting to ARM9.

Source: Internet
Author: User

Project requirements: Cross-compile opencv2.3.1 and port it to mini2440. I will share my experiences and errors as follows, hoping to help you. Note: For opencv2.0 or later versions, makefile must be generated by using the cmake tool. The Versions earlier than 2.0 are generally

Use./configure to generate makefile.

I. Development Environment

Host Computer: fedora9.0

Cross Compiler: arm-linux-gcc4.4.3 (offered by friendly arm)

Cmake-2.8.7-Linux-i386.sh

Ii. Install the cross-compilation tool chain

My installation directory is/opt/toolchain/4.4.3

Add environment variable: add the bin path of the Cross-compilation toolchain to the path environment variable:/opt/toolchain/4.4.3/bin (depending on your installation path)

3. Install cmake

There are also cmake GUI versions in Linux. As mentioned above, you can search for them online and there are many download links.

Installation Procedure: Modify the execution permission for the cmake-2.8.7-Linux-i386.sh in Linux

[Root @ localhost opt] # chmod + x cmake-2.8.7-Linux-i386.sh (modified to executable permission)

Run cmake-2.8.7-Linux-i386.sh:

[Root @ localhost opt] #./cmake-2.8.7-Linux-i386.sh
Press enter to decompress the cmake-2.8.7-Linux-i386 folder in the current directory and enter the folder:

[Root @ localhost opt] # cd cmake-2.8.7-Linux-i386
You can find the bin, include, and other directories in the directory and enter the bin directory:

[Root @ localhost cmake-2.8.7-Linux-i386] # cd Bin

It can be found that the bin directory contains executable files such as cmake-Gui, cmake, and ccmake.

On the Linux GUI, run the cmake-Gui file:

[Root @ localhost bin] #./cmake-Gui

The following page is displayed:

Select source code Directory:/opt/OpenCV-2.31
Select the build Directory:/opt/opencv2.3.1 _ forarm. Set the compiling directory according to your preferences.

Click Configure, keep generator as UNIX makefiles, select specify options for cross-compiling, and click Next
Set Operating System to arm-inux.
C compilers fill in/opt/toolchain/4.4.3/bin/ARM-Linux-gcc
C ++ compilers fill in/opt/toolchain/4.4.3/bin/ARM-Linux-G ++
Enter/opt/toolchain/4.4.3/bin/as the target root of the library, and click Finish, as shown in:

The directory marked above indicates the directory to be installed by opencv. The default value is/usr/local. To facilitate management, you can install it in your own directory and modify it: also, I do not have support for installing tiff images, so remove with_tiff (from: http://blog.csdn.net/eagelangel/article/details/7232364 ). But I did not. Click Configure here, and then click gennerate to generate the makefile.

Go to the/opt/opencv2.3.1 _ forarm directory and run the make command to compile opencv. the following error occurs during compilation:

In File sorted ded from/opt/OpenCV-2.3.1/modules/FLANN/src/precomp. HPP: 9,
From/opt/opencv2.3.1 _ forarm/modules/FLANN/opencv_flann_pch_dephelp.cxx: 1:
/Opt/OpenCV-2.3.1/modules/FLANN/include/opencv2/FLANN/Dist. H: In function't cvflann: ABS (t) [with T = Long Double] ':
/Opt/OpenCV-2.3.1/modules/FLANN/include/opencv2/FLANN/Dist. h: 63: Error: 'fabsl 'was not declared in this scope
Make [2]: *** [modules/FLANN/cmakefiles/opencv_flann_pch_dephelp.dir/opencv_flann_pch_dephelp.obj] Error 1
Make [1]: *** [modules/FLANN/cmakefiles/opencv_flann_pch_dephelp.dir/All] Error 2
Make: *** [all] Error 2

Solution: Modify OpenCV-2.3.1/modules/FLANN/include/opencv2/FLANN/Dist. h file source code for line 1: Change absl () to ABS ()

If the compilation process encounters the following error:

Linking cxx executable.../../bin/opencv_test_calib3d
.../../Lib/libopencv_core.so: Undefined reference to 'pthread _ key_create'
.../../Lib/libopencv_core.so: Undefined reference to 'pthread _ getspecific'
.../../Lib/libopencv_ts.so: Undefined reference to 'pthread _ key_delete'
.../../Lib/libopencv_core.so: Undefined reference to 'pthread _ once'
.../../Lib/libopencv_core.so: Undefined reference to 'clock _ gettime'
.../../Lib/libopencv_core.so: Undefined reference to 'pthread _ setspecific'
Collect2: LD returned 1 exit status
Make [2]: *** [bin/opencv_test_calib3d] Error 1
Make [1]: *** [modules/calib3d/cmakefiles/opencv_test_calib3d.dir/All] Error 2
Make: *** [all] Error 2

Solution: Modify cmakecache.txt and cmake_exe_linker_flags in the/opt/opencv2.3.1directory, and add-lpthread-LRT, for example:

Note: after each error is generated, you only need to execute the make command again and then compile it. After the compilation is successful, run the make intall command to install opencv.

Since my installation directory is/opt/opencv2.3.1 _ arm, you can see that the bin, Lib, include, and other directories are generated as follows:

Many dynamic library files can be found in the lib directory, as follows:

Now, opencv cross-compilation is successful. Time is too short to avoid omissions in this article.

I write this article refer to the eagelangel blog, here to express thanks, blog Source: http://blog.csdn.net/eagelangel/article/details/7232364

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.