开发者

LD: linking with STL libraries

I was trying to compile a OpenCV's VideoCapture example. When I compile it, I get the following output:

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.

(Btw, gpp is an al开发者_StackOverflow社区ias to g++ -lhighgui -lcv -lcxcore)

So, I tried to compile with "gpp --enable-auto-import", but g++ didn't recognize this option. So, I tried to compile like this:

gpp -c test.c
ld test.o

And I've got the same error AND many other errors about STL functions, indicating it didn't link with STL:

undefined reference to std::cout
...

And, finally, when I compiled like this:

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

This time, I've only got the STL errors. The VideoCapture error is gone! So I guess I solved this problem. The only thing is: how do I make ld link my program with STL libraries??????

Thanks in advance


The correct solution is build with

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

Unlike your 'gpp' alias, this puts libraries after objects which reference them (important when linking with archive libraries), and also properly passes --enable-auto-import flag to the linker.

Your current "fix" only works "by accident".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜