静态链接 OpenCV



我想编译一个静态使用 openCV 的C++程序,这样我就可以在其他计算机上使用它,而无需安装 openCV。

我使用以下标志编译了 openCV 2.4.5,以便获取静态库并在我的主安装版本 3.1 之外安装它。

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/openCV_2_4_5 -D WITH_FFMPEG=OFF -DBUILD_SHARED_LIBS=NO ..
ls /opt/openCV_2_4_5/lib
libopencv_calib3d.a     libopencv_flann.a    libopencv_legacy.a     libopencv_photo.a      libopencv_video.a
libopencv_contrib.a     libopencv_gpu.a      libopencv_ml.a         libopencv_stitching.a  libopencv_videostab.a
libopencv_core.a        libopencv_highgui.a  libopencv_nonfree.a    libopencv_superres.a   pkgconfig
libopencv_features2d.a  libopencv_imgproc.a  libopencv_objdetect.a  libopencv_ts.a         python2.7

安装后,我尝试编译一个用于人脸检测的 c++ 程序,如下所示:

g++ -std=c++11 -L/opt/openCV_2_4_5/lib -I/opt/openCV_2_4_5/include -o ex2 ex2.cpp -L. -lpthread -lz -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core

从那我得到错误:

/tmp/cct4prBn.o: In function `main':
ex2.cpp:(.text+0x141): undefined reference to `cv::imread(std::string const&, int)'
ex2.cpp:(.text+0x2bc): undefined reference to `cv::imread(std::string const&, int)'
ex2.cpp:(.text+0x4f3): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status
make_2_4_5:9: recipe for target 'ex2' failed
make: *** [ex2] Error 1

我使用了与OpenCV 3.1安装相同的库标志。我从以下方面得到它们:

pkg-config --cflags --libs opencv

-L 和 -I 标志指向/opt 目录中的 openCV 2.4.5 安装。

为什么不编译?所有 OpenCV 库都列在静态库应位于的部分中。

在 OpenCV 2 中,我相信cv::imread()cv::imwrite()都在highgui库中。在OpenCV 3中,它们被移动到imgcodecs库中。 尝试添加:

-lopencv_highgui

到您的命令行。

相关内容

  • 没有找到相关文章