Mingw and Eclipse unable to find library

2019-07-16 11:49发布

问题:

I'm having the issues simlar to what's described here. I created a new project, added the library path in Eclipse and added the name of the library to use. But the MingW linker can't find the library. I've tried using "/" instead of "\" (this was the solution to the issue Iiked to), as well as several other things, but no luck. Couldn't find anything that worked in the mingw documentation.

My command is as follows:

g++ -LD:/ocv/build/x86/mingw/lib -o OCVTest.exe "src\\OCVTest.o" -ltest.a 
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot find -ltest.a
collect2.exe: error: ld returned 1 exit status

The file is called test.a

In command line I tried using

g++ -L"D:/ocv/build/x86/mingw/lib" -o OCVTest.exe "src\\OCVTest.o" -ltest.a 

But this didn't help either.

I installed MingW and Make for Windows. I added both of those to my PATH variable.

回答1:

name it libtest.a and use -ltest option to g++. static libs in *nix (include mingw) supposed to be named like libxxx.a, -l option tells to compiler to find libraries in specified paths (current and given via -L option(s)). but to link w/ static lib one may give a fullname (w/o any option)... just pass libtest.a