Opencv static compilation in ubuntu12.04
Opencv static compilation in ubuntu12.04
1.12.04, because there is no new model, it cannot stand the slowness of the Software Center, so the new model is installed.
Apt-Get install synaptic
2. Install C/C ++ programming tools such as gcc
Sudo apt-Get install build-essential
3. Install GTK + (it depends on the display of opencv Interface)
To install the GTK environment, you only need to install libgtk2.0-Dev. to install the gnome development environment, you need to install gnome-core-devel, which contains the GTK development kit.
Sudo apt-Get install gnome-core-devel (a little slow, need to download, view the network speed)
PKG-config -- modversion GTK + (view version 1.2.x)
PKG-config -- modversion GTK +-2.0 (view version 2.x)
PKG-config -- version (view the version of PKG-config)
PKG-config -- list-All | grep GTK (check whether GTK is installed)
4. Use synaptic to install cmake-QT
It is easier to configure the opencv compilation option with the interface cmake.
5. Install wxWidgets (codeblocks ide required) v2.8 (for details, see)
Since codeblocks is developed using wxWidgets, wxWidgets needs to be installed first. for the purpose of compiling with minimal size, the shared, Unicode version, library file is compiled into a file, 2.8 is not supported, the debug information is removed, and the final configuration command is as follows (. /configure -- help to view the parameter information ):
./Configure -- enable-Unicode -- enable-shared -- enable-monolithic -- disable-compat28 -- disable-debug_flag
Make (takes some time)
Make install
Ldconfig (Add/usr/local/lib to the last line of/etc/lD. So. conf, and then execute ldconfig)
The compiled file is stored in the/usr/local/bin and/usr/local/lib directories. You can change the path through-prefix.
Since codeblocks currently only supports 2.8, uninstall make Uninstall. reinstall 2.9.
./Configure -- enable-Unicode -- enable-shared -- enable-monolithic -- disable-compat26 -- disable-debug_flag
Make (takes some time)
Make install
6. Install codeblocks (ver10.05)
Codeblocks Latest Version 10.05 (as of) can only use wxwidgets2.8, incompatible 2. 9. the following error occurs when you use 2.9: editarrayorderdlg. h: 20: Error: Default argument for parameter of Type 'const wxarraystring & 'hastype 'long int '. wxWidgets must be compiled into a single file. the Build File under the source code contains the compilation instructions. execute the following three commands in sequence.
./Configure -- With-contrib-plugins = all
Make
Make install
After the installation is complete, open it and only find that it disappears after a flash in the taskbar. The interface cannot be displayed. run the following command on the terminal: codeblocks: Error while loading shared libraries: libcodeblocks. so.0: cannot open your dobject file: no such file or directory
Solution: In that case make sure the library path where the code: blocks librarieswhere installed into is "known" to the system. for example: on ubuntuusing a default build process on a clean system will install the code: blocksexecutables to/use/local/bin
And the libraries to/usr/local/lib. the latteris usually not known to a "clean" ubuntu system. to add it to thesearch path for libraries do the following (as root/using sudo respectively): Add the following line to the file/etc/lD. so. conf:
/Usr/local/lib
... And run:
Ldconfig
That's it-code: blocks shocould now work just fine asall libraries are being found.
Wxsmith is unavailable. When CB is enabled, the following message is displayed:
/Usr/local/lib/codeblocks/plugins/libwxsmithaui. So: Not loaded (missing symbols ?)
/Usr/local/lib/codeblocks/plugins/libwxsmithcontribitems. So: Not loaded (missing symbols ?)
/Usr/local/lib/codeblocks/plugins/libwxsmith. So: notloaded (missing symbols ?)
Run sudo ldconfig.
7. Install FFMPEG (ver0.10.3)
Install FFMPEG first.Yasm), Download the source code,
./Configure -- enable-shared (dynamic link required)
Make
Makeinstall
Ldconfig.
If the machine has installed FFMPEG before, uninstall it first. I used synaptic to install version 0.8, and finally used synaptic to uninstall it. However, library files such as libav * still exist, so how to compile FFmpeg is linked to those libraries of version 0.8 will cause errors.
As long as the libavdevice, filter, format, codec, swresample, swscale, and avutil libraries are linked to the following directories, they are linked to the old files.
/Usr/lib/i386-linux-gnu/,/usr/lib/i386-linux-gnu/i686/cmov /. The link to the/usr/local/lib directory is correct.
Solution:
Delete/usr/lib/i386-linux-gnu/,/usr/lib/i386-linux-gnu/i686/cmov/corresponding files in these two directories, and then re-ldconfig, LDD 'which FFMPEG 'to check the link of the FFMPEG library. If all links are to the relevant libraries in the/usr/local/lib directory, the operation is successful. Otherwise, the related library files in the above two directories are deleted and then compiled.
8. Install opencv (ver2.4.2)
Use cmake to compile,
Cancel build_jasper jpeg png tiff zlib (Linux idea is to share, so use the image library of the system, if not, install it first)
Build_shared_libsbuild_perf_tests build_tests)
After compilation and installation are complete, use PKG-config to view the header file and library file information.
Root @ Ubuntu :~ # PKG-config opencv -- cflags
// View the contained directory
-I/usr/local/include/opencv-I/usr/local/include
Root @ Ubuntu :~ # PKG-config opencv -- libs
// View the Library link. The format is incorrect and there is no-L and-l id. Therefore, you must add
/Usr/local/lib/libopencv_contrib.a/usr/local/lib/users/usr/local/lib/libopencv_ml.a/usr/local/lib/users/usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_videostab.a/usr/local/lib/libopencv_gpu.a/usr/local/lib/libopencv_nonfree.a
/Usr/local/lib/release/usr/local/lib/libopencv_calib3d.a/usr/local/lib/libopencv_photo.a/usr/local/lib/libopencv_video.a/usr/local/lib/release /usr/local/lib/libopencv_highgui.a/usr/local/share/opencv/3 rdparty/lib/liblibjasper. a/usr/local/share/opencv/3 rdparty/lib/liblibtiff. a/usr/local/share/opencv/3 rdparty/lib/liblibpng. a/usr/local/share/opencv/3 rdparty/lib/liblibjpeg. a/usr/local/lib/libopencv_flann.a
/Usr/local/lib/libopencv_imgproc.a/usr/local/lib/libopencv_core.a/usr/local/share/opencv/3 rdparty/lib/libzlib. aswscale avformat avutil Z avcodec gstvideo-0.10 gstapp-0.10 xml2 gmodule-2.0gstreamer-0.10 gstbase-0.10 gthread-2.0 glib-2.0 gobject-2.0 fontconfigfreetype
Pango-1.0 Cairo gdk_pixbuf-2.0 pangocairo-1.0 pangoft2-1.0 gio-2.0atk-1.0 gdk-x11-2.0 gtk-x11-2.0 RT pthread m dl stdc ++
9. Test opencv
Header file location settings: Add 'pkg-config opencv -- cflags 'to project-build option-compiler settings -- otheroptions in codeblocks'
Library Link parameter settings: Add 'pkg-config opencv -- libs' to project-build option-linker settings -- Other linkeroptions in codeblocks ', the preceding figure shows that the libs format obtained by opencv after static compilation is not correct. Therefore, you must manually change it to the correct format before outputting the libs format to otherlinker options (for specific parameters, see the following table for analysis ).
Package Including Industry Surface Library (Highgui) |
Jing Status Chain Connect (-Static) |
Chain Connect Parameter Quantity |
-Static-upgrade-lopencv_legacy-lopencv_ml-lopencv_stitching-upgrade-lopencv_gpu-lopencv_nonfree-upgrade-lopencv_photo-lopencv_video-upgrade-lopencv_highgui -Llibjasper-llibtiff-llibpng-llibjpeg -Lopencv_flann-lopencv_imgproc-lopencv_core -Lswscale-lavformat-lavcodec-lavutil-LVA-lzlib-lgtk-x11-2.0-lgdk-x11-2.0-latk-1.0-lgio-2.0-lpangoft2-1.0-lpangocairo-1.0-lgdk_pixbuf-2.0-lcairo-lpango-1.0-lfreetype-lfontconfig-lgobject-2.0-lglib-2.0-lgthread-2.0 -LRT-lpthread -Lm-LDL-lstdc ++ |
Link failed |
Generate File Dependency Item |
Link failed: In GTK, The ATK and gdk_pixbuff libraries only have dynamic libraries and do not have static tables. Therefore, links cannot be expressed. Installing static libraries for these libraries can solve the problem. |
Dynamic Status Chain Connect (-Shared) |
Chain Connect Parameter Quantity |
-Upgrade-lopencv_legacy-lopencv_ml-lopencv_stitching-upgrade-lopencv_gpu-lopencv_nonfree-upgrade-lopencv_calib3d-lopencv_photo -Llibjasper-llibtiff-llibpng-llibjpeg -Lopencv_flann-lopencv_imgproc-lopencv_core -Lswscale-lavformat-lavcodec-lavutil-LVA-lzlib-lgtk-x11-2.0-lgdk-x11-2.0-latk-1.0-lgio-2.0-lpangoft2-1.0-lpangocairo-1.0-lgdk_pixbuf-2.0-lcairo-lpango-1.0-lfreetype-lfontconfig-lgobject-2.0-lglib-2.0-lgthread-2.0 -LRT-lpthread -Lm-LDL-lstdc ++ |
Succeeded and can run |
Raw Cheng Text Parts Yi Lai Item |
Linux-gate.so.1 libva. so.1 libgtk-x11-2.0.so.0 libgdk-x11-2.0.so.0 libgobject-2.0.so.0 libglib-2.0.so.0 librt. so.1 libpthread. so.0 libstdc ++. so.6 libm. so.6 libgcc_s.so.1 libc. so.6 libdl. so.2 libpangocairo-1.0.so.0 libx11.so. libxfixes. so.3 Libatk-1.0.so.0 libcairo. so.2 libgdk_pixbuf-2.0.so.0 libgio-2.0.so.0 libpangoft2-1.0.so.0 libpango-1.0.so.0 .. so.1 libxext. so.6 libxrender. so.1 protocol. so.1 libxi. so.6 libxrandroid. so.2 libxcursor. so.1 protocol. so.1 libxdamage. so.1 ibffi. so.6 Libpcre. so.3/lib/ld-linux.so.2 libfreetype. so.6 libxcb. so.1 libpixman-1.so.0. 0 libxcb-shm.so.0 libxcb-render.so.0 libz. so.1 libgmodule-2.0.so.0 libselinux. so.1 libresolv. so.2 libexpat. so.1 libxau. so.6 release. so.6 |
No Package Including Industry Surface Library (Highgui) |
Jing Status Chain Connect (-Static) |
Chain Connect Parameter Quantity |
-Static-L/usr/local/lib-L/usr/local/share/opencv/3 rdparty/lib -Upgrade-lopencv_legacy-lopencv_ml-lopencv_stitching-upgrade-lopencv_gpu-lopencv_nonfree-upgrade-lopencv_calib3d-lopencv_photo -Llibjasper-llibtiff-llibpng-llibjpeg -Lopencv_flann-lopencv_imgproc-lopencv_core-lzlib -Lswscale-lavutil-lavformat-lavcodec -Lxml2-lgmodule-2.0-lgstreamer-0.10-lgstbase-0.10 -Lgthread-2.0-lglib-2.0-lgobject-2.0-lfontconfig-lfreetype-lpango-1.0-lcairo-lpangocairo-1.0-lpangoft2-1.0-lgio-2.0-lgdk-x11-2.0-lgtk-x11-2.0 -LDL-lm-lpthread-LRT-lstdc ++ |
Succeeded and can run |
Generate file Dependencies |
The target program does not link the dynamic library not a dynamic executable, that is, it does not depend on any file, than Ms. |
Dynamic Status Chain Connect (-Shared) |
Chain Connect Parameter Quantity |
-Shared-L/usr/local/lib-L/usr/local/share/opencv/3 rdparty/lib -Upgrade-lopencv_legacy-lopencv_ml-lopencv_stitching-upgrade-lopencv_gpu-lopencv_nonfree-upgrade-lopencv_calib3d-lopencv_photo -Llibjasper-llibtiff-llibpng-llibjpeg -Lopencv_flann-lopencv_imgproc-lopencv_core-lzlib -Lswscale-lavutil-lavformat-lavcodec -Lxml2-lgmodule-2.0-lgstreamer-0.10-lgstbase-0.10 -Lgthread-2.0-lglib-2.0-lgobject-2.0-lfontconfig-lfreetype-lpango-1.0-lcairo-lpangocairo-1.0-lpangoft2-1.0-lgio-2.0-lgdk-x11-2.0-lgtk-x11-2.0 -LDL-lm-lpthread-LRT-lstdc ++ |
Unable to run, prompt illegal instruction (core dumped) |
Generate File Dependency Item |
Linux-gate.so.1 => (0x00f82000) Libpthread. so.0 =>/lib/i386-linux-gnu/libpthread. so.0 (0x00a02000) Librt. so.1 =>/lib/i386-linux-gnu/librt. so.1 (0x00ea4000) Libstdc ++. so.6 =>/usr/lib/i386-linux-gnu/libstdc ++. so.6 (0x0030d000) Libm. so.6 ==>/lib/i386-linux-gnu/libm. so.6 (0x008e6000) Libc. so.6 =>/lib/i386-linux-gnu/libc. so.6 (0x00bf2000) /Lib/ld-linux.so.2 (0x005ec000) Libgcc_s.so.1 =>/lib/i386-linux-gnu/libgcc_s.so.1 (0x003f2000) |
Error handling:
/Usr/bin/ld: cannot find-lgstvideo-0.10
/Usr/bin/ld: cannot find-lgstapp-0.10
/Usr/bin/ld: cannot find-lgdk_pixbuf-2.0
/Usr/bin/ld: cannot find-latk-1.0
(Using the-static parameter will result in the above error) Remove-lgstvideo-0.10-lgstapp-0.10-lgdk_pixbuf-2.0-latk-1.0 in the Library Link parameter (each corresponds to an error)