0

I am using Windows 10 with mingw-w64. I tried compiling a program with a statically linked library. I used this command: g++ main.cpp -Llibs/ -lfoo. But MinGW says it can't find the library files, so I tried renaming foo.a to foo.lib and voila, the compiler found foo.lib. Why doesn't MinGW see *.a files anymore?

2 Answers2

0

From the documentation:

when ld is called with the argument ‘-lxxx’ it will attempt to find, in the first directory of its search path,

  • libxxx.dll.a
  • xxx.dll.a
  • libxxx.a
  • xxx.lib
  • libxxx.lib
  • cygxxx.dll
  • libxxx.dll
  • xxx.dll

Alternatively, you can pass libs/foo.a directly as an argument to g++.

Community
  • 1
  • 1
Botje
  • 26,269
  • 3
  • 31
  • 41
0

The problem is that mingw will not look for <libname>.a files because it does not expect them to exist.

From the docs:

MinGW supports libraries named according to the ".lib" and ".dll" conventions, in addition to the normal "lib.a" convention common on *nix systems

This is because windows does not use the lib prefix for its libraries in the same way that *nix does (on windows a shared library foo would be foo.dll and on *nix it would be libfoo.so). I am not sure how you managed to get a .a missing the lib prefix (unless you renamed it) but your .a files should have a lib prefix in them (when specifying this you omit the lib part so libfoo.a becomes -lfoo)

Object object
  • 1,939
  • 10
  • 19