未定义的符号引用但链接了库

时间:2015-10-08 15:38:48

标签: c++ shared-libraries opencv3.0

我正在尝试使用opencv 3.0构建一个应用程序,我得到一个“未定义的符号错误引用”

我的问题是符号是在我链接的库中定义的。

编译命令:

g++ -o DisparityMap main.o tools.o emb.o moc_tools.o moc_emb.o -lopencv_highgui -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_calib3d -lQtGui -lQtCore -lpthread

我得到的错误:

/usr/bin/ld: twowindow.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
//usr/local/lib/libopencv_core.so.3.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

但有问题的符号实际上是在我链接到的库中定义的:

scanelf -l -s _ZN2cv6String10deallocateEv | grep _ZN2cv6String10deallocateEv

ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_objdetect.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_photo.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_core.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_video.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_features2d.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_ml.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_highgui.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_videoio.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_stitching.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_videostab.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_superres.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_flann.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_imgproc.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_imgcodecs.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_calib3d.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_shape.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_objdetect.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_photo.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_core.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_video.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_features2d.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_ml.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_highgui.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_videoio.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_stitching.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_videostab.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_superres.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_flann.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_imgproc.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_imgcodecs.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_calib3d.so.3.0.0 
ET_DYN _ZN2cv6String10deallocateEv /usr/local/lib/libopencv_shape.so.3.0.0 

2 个答案:

答案 0 :(得分:0)

  

编译命令:

这是不是编译命令,它是 link 命令。

  

我得到的错误:

错误引用twowindow.o,链接命令

因此,很难相信错误确实来自您提供的链接命令。

最有可能的是,错误来自不同的链接命令, 链接命令没有-lopencv_core

答案 1 :(得分:0)

在链接库之前,请给出带-L标志的路径。