【问题标题】:LD: linking with STL librariesLD:与 STL 库链接
【发布时间】:2011-04-09 05:51:57
【问题描述】:

我试图编译 OpenCV 的 VideoCapture 示例。当我编译它时,我得到以下输出:

gpp test.c
Info: resolving vtable for cv::VideoCapture by linking to __imp___ZTVN2cv12VideoCaptureE (auto-import)
c:/programs/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: auto-importing has
enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.

(顺便说一句,gpp 是 g++ -lhighgui -lcv -lcxcore 的别名)

所以,我尝试使用“gpp --enable-auto-import”进行编译,但 g++ 无法识别此选项。所以,我尝试这样编译:

gpp -c test.c
ld test.o

我遇到了同样的错误,还有很多关于 STL 函数的其他错误,表明它没有与 STL 链接:

undefined reference to std::cout
...

最后,当我这样编译时:

gpp -c test.c
ld --enable-auto-import test.o

这一次,我只遇到了 STL 错误。 VideoCapture 错误消失了!所以我想我解决了这个问题。唯一的问题是:如何使 ld 将我的程序与 STL 库链接??????

提前致谢

【问题讨论】:

  • 解决了。虽然 ld 上的参数是“--enable-auto-import”,但在使用 g++ 编译时,您只能使用“-enable-auto-import”。这样,我就能够编译并运行我的示例。

标签: g++ opencv ld


【解决方案1】:

正确的解决方案是使用

g++ test.c -lhighgui -lcv -lcxcore -Wl,--enable-auto-import

与您的“gpp”别名不同,这会将库放在引用它们的对象之后(在与存档库链接时很重要),并且还会正确地将 --enable-auto-import 标志传递给链接器。

您当前的“修复”只能“偶然”起作用。

【讨论】:

    猜你喜欢
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 2014-03-14
    • 2012-07-20
    • 2023-03-11
    • 1970-01-01
    相关资源
    最近更新 更多