gpt4 book ai didi

c++ - linux编译-库冲突

转载 作者:太空宇宙 更新时间:2023-11-04 09:18:37 26 4
gpt4 key购买 nike

所以我不是在电脑上工作,而是在运行 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

最佳答案

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

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

在您的例子中,2.4 版本的库位于 /usr/lib 中,而 3.2 版本的库位于 /usr/local/lib 中。您的代码可能需要 2.4 版本,但您的系统可能设置为在搜索 /usr/lib 之前搜索 /usr/local/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 )

关于c++ - linux编译-库冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44391324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com