如何在编译OpenCV时纠正“未定义的引用”错误?

时间:2015-07-26 07:39:51

标签: c++ opencv

我已经从OpenCV官方网站下载了c ++中的Eigenfaces算法,我用这个命令编译它:

g++ `pkg-config --cflags --libs opencv` facerec_eigenfaces.cpp -o opencv

但是我得到了这些错误:

/tmp/cc0CsJ0b.o: In function `norm_0_255(cv::_InputArray const&)':
facerec_eigenfaces.cpp:(.text+0x51): undefined reference to `cv::noArray()'
facerec_eigenfaces.cpp:(.text+0x65): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facerec_eigenfaces.cpp:(.text+0x9b): undefined reference to `cv::normalize(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, int, cv::_InputArray const&)'
facerec_eigenfaces.cpp:(.text+0xa2): undefined reference to `cv::noArray()'
facerec_eigenfaces.cpp:(.text+0xb6): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facerec_eigenfaces.cpp:(.text+0xec): undefined reference to `cv::normalize(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, int, cv::_InputArray const&)'

我不会在这里复制所有主题,但它们都是“未定义的引用”,我的OpenCV版本与我提到的链接相同。

(pkg-config --cflags --libs opencv)的输出:

-I/usr/local/include/opencv -I/usr/local/include  /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so /usr/local/lib/libopencv_viz.so /usr/lib/i386-linux-gnu/libXext.so /usr/lib/i386-linux-gnu/libX11.so /usr/lib/i386-linux-gnu/libICE.so /usr/lib/i386-linux-gnu/libSM.so /usr/lib/i386-linux-gnu/libGL.so /usr/lib/i386-linux-gnu/libGLU.so -ltbb -lrt -lpthread -lm -ldl 

1 个答案:

答案 0 :(得分:3)

假设。

尝试将链接器标志移动到命令的末尾:

g++  facerec_eigenfaces.cpp -o opencv `pkg-config --cflags --libs opencv`

另请参阅:Why does the order in which libraries are linked sometimes cause errors in GCC?