c++ - 在 Ubuntu 上链接 OpenCV 2.3.1

标签 c++ opencv linker

我是 OpenCV 的新手,我遇到了链接问题。

我使用的是 Ubuntu 11.10,OpenCV 2.3.1 是根据 this 安装的指南:

我正在用它构建许多小型应用程序,它看起来不错。 通常,我使用 pkg-config --libs --cflags opencv 构建。

现在,我正在尝试构建其他人编写的一些框架,它编译没有任何问题,但我无法链接它:有一长串“ Unresolved 引用...”(其中有数千个) ).未找到与 opencv_core 相关的所有符号。

我尝试在没有预编译 header 支持的情况下重新编译 OpenCV,但没有帮助。当然。 :(

test_opencv_core 应用程序运行良好,但 opencv_rand 失败。我认为它说 opencv_core 是正确的,一般来说,但是当我需要它时它仍然不起作用......

你能给我一些提示吗?我迷路了。

先谢谢你, 大卫

更新: 已解决。

gcc 4.6.1 要求库和源代码在命令行中出现在共享库路径之前。为什么?不知道。刚刚为这个愚蠢的错误花了 24 小时:(

更新: 可以理解。 来自 ld 手册页:

The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.

See the -( option for a way to force the linker to search archives multiple times.

就是这样。

最佳答案

gcc 4.6.1 要求库和源代码出现在命令行中共享库路径之前。我不知道为什么。

更新: 可以理解。 来自 ld 手册页:

The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.

See the -( option for a way to force the linker to search archives multiple times.

就是这样。

关于c++ - 在 Ubuntu 上链接 OpenCV 2.3.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9156840/

相关文章:

c++ - 受比较器约束的数据结构

c++ - 我的 RNG 值确定意外值

opencv - 使用opencv进行形状检测的形状

c - 对带有 -Wl,--wrap 的包装函数的 undefined reference

c - C程序立即执行后退出,但它有一个while(1)循环

c++ - 使用 MySql 数据库打包 C++ 应用程序

c++ - 区分读取循环中的失败和文件结尾

python - 图像上像素(X,Y)的颜色强度 [OpenCV/Python]

python - Opencv单应性从像素xy坐标找到全局xy坐标

c - 链接 c 文件时覆盖变量