linux编译 - 冲突的库

时间:2017-06-06 13:27:37

标签: c++ linux opencv

所以我不是在计算机上工作,而是在运行ubuntu的嵌入式设备上工作。

我正在尝试编译openCV代码,但我觉得我陷入了僵局!

这是我得到的错误: 问题:

/usr/bin/ld: warning: libopencv_core.so.3.2, needed by //usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_core.so.2.4
/usr/bin/ld: /tmp/ccYlsBYW.o: undefined reference to symbol '_ZN2cv11setIdentityERKNS_17_InputOutputArrayERKNS_7Scalar_IdEE'
/usr/local/lib//libopencv_core.so.3.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

重命名2.4库:

ubuntu@tegra-ubuntu:/usr/lib$ sudo mv libopencv_core.so libopencv_core.soMyOld
ubuntu@tegra-ubuntu:/usr/lib$ sudo mv libopencv_core.so.2.4 libopencv_core.so.2.4MyOld
ubuntu@tegra-ubuntu:/usr/lib$ sudo mv libopencv_core.so.2.4.10 libopencv_core.so.2.4.10MyOld

重新编译代码

/usr/bin/ld: warning: libopencv_core.so.2.4, needed by /usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../../lib/libopencv_imgproc.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libopencv_imgproc.so.3.2, needed by //usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_imgproc.so.2.4
/usr/bin/ld: /tmp/ccmcvWug.o: undefined reference to symbol '_ZN2cv6circleERKNS_17_InputOutputArrayENS_6Point_IiEEiRKNS_7Scalar_IdEEiii'
/usr/local/lib//libopencv_imgproc.so.3.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

重命名3.2库:

ubuntu@tegra-ubuntu:/usr/local/lib$ sudo mv libopencv_core.so 
ubuntu@tegra-ubuntu:/usr/local/lib$ sudo mv libopencv_core.so.3.2 libopencv_core.so.3.2MyOld
ubuntu@tegra-ubuntu:/usr/local/lib$ sudo mv libopencv_core.so.3.2.0 libopencv_core.so.3.2.0MyOld

重新编译

/usr/bin/ld: warning: libopencv_core.so.3.2, needed by //usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libopencv_imgproc.so.3.2, needed by //usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_imgproc.so.2.4
/usr/bin/ld: /tmp/cclHSHtB.o: undefined reference to symbol '_ZN2cv6circleERKNS_17_InputOutputArrayENS_6Point_IiEEiRKNS_7Scalar_IdEEiii'
/usr/local/lib//libopencv_imgproc.so.3.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

我该怎么做才能解决这个问题?卸载所有内容并重新安装不是一个选项......

修改

我用这个命令编译:

g++ src/personDetection.cpp src/personRecognition.cpp main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_calib3d -lopencv_features2d -lopencv_video -lopencv_videoio -pthread -o main

1 个答案:

答案 0 :(得分:1)

-L选项用于指定目录路径。编译器将使用其他系统标准目录搜索此目录,例如LIBRARY_PATH中的目录。 但它会先搜索使用-L指定的目录

-l选项用于指定库的名称

在您的情况下,2.4版本库位于/usr/lib中,3.2版本库位于/usr/local/lib中。您的代码可能需要2.4版本,但您的系统可能会设置为在搜索/usr/local/lib之前搜索/usr/lib,这可能是导致问题的原因。

通过指定-L/usr/lib,您告诉编译器首先搜索/usr/lib,导致使用2.4版本库。

<强>更新

$ gcc -m64 -Xlinker --verbose  2>/dev/null | grep SEARCH | sed 's/SEARCH_DIR("=\?\([^"]\+\)"); */\1\n/g'  | grep -vE '^$'

上面的命令将显示链接时默认搜索目录的列表。 (从this article

复制命令

在我的机器(Ubuntu 16.04,64位)中,/usr/local/lib出现在/usr/lib之前。这意味着/usr/local/lib中的库可以覆盖/usr/lib中的库。 (link