linux编译-冲突的库 [英] linux compilation - conflicting libraries

查看:591
本文介绍了linux编译-冲突的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I am not working on a computer but on an embedded device running ubuntu.

我正在尝试编译openCV代码,但是我感觉自己陷入了僵局!

I am trying to compile openCV code but I have the feeling that I am in a deadlock!

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

This is the error I get: problem:

/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

我该怎么做才能解决此问题?不能卸载所有内容并重新安装...

What can I do to solve this issue? Uninstalling everything and reinstalling is not an option...

我使用以下命令进行编译:

I compile with this command:

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

推荐答案

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

-L option is used to specify the directory path. Compiler will search this directory with other system standard directories, such as directories in LIBRARY_PATH. But it searches directories specified with -L first.

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

在您的情况下,2.4版本库位于/usr/lib中,而3.2版本库位于/usr/local/lib中.您的代码可能正在使用2.4版本,但是您的系统可能已设置为在搜索/usr/lib之前先搜索/usr/local/lib,这可能是导致问题的原因.

In your case, 2.4 version libraries are in /usr/lib and 3.2 version libraries are in /usr/local/lib. Your code, probably, is expecting 2.4 version, but your system may be set to search /usr/local/lib before searching /usr/lib and this may be the cause of your problem.

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

By specifying -L/usr/lib you are telling compiler to search /usr/lib first, resulting in using 2.4 version libraries.

更新

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

上面的命令将在链接时显示默认搜索目录的列表. (从本文复制了命令)

Above command will show you the list of default searched directories when linking. (copied the command from this article)

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

In my machine(Ubuntu 16.04, 64-bit), /usr/local/lib appears before /usr/lib. This means that a library in /usr/local/lib can override libraries in /usr/lib. (link)

这篇关于linux编译-冲突的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆