[英]g++ only looks for .lib files
I am using Windows 10 with mingw-w64.我正在使用 Windows 10 和 mingw-w64。 I tried compiling a program with a statically linked library.
我尝试使用静态链接库编译程序。 I used this command:
g++ main.cpp -Llibs/ -lfoo
.我使用了这个命令:
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
.但是 MinGW 说它找不到库文件,所以我尝试将
foo.a
重命名为foo.lib
和瞧,编译器找到foo.lib
。 Why doesn't MinGW see *.a
files anymore?为什么 MinGW 不再看到
*.a
文件了?
From the documentation :从文档中:
when ld is called with the argument '-lxxx' it will attempt to find, in the first directory of its search path,
当使用参数“-lxxx”调用 ld 时,它将尝试在其搜索路径的第一个目录中查找,
- libxxx.dll.a
libxxx.dll.a
- xxx.dll.a
xxx.dll.a
- libxxx.a
libxxx.a
- xxx.lib
xxx.lib
- libxxx.lib
libxxx.lib
- cygxxx.dll
cygxxx.dll
- libxxx.dll
libxxx.dll
- xxx.dll
xxx.dll
Alternatively, you can pass libs/foo.a
directly as an argument to g++
.或者,您可以将
libs/foo.a
作为参数直接传递给g++
。
The problem is that mingw will not look for <libname>.a
files because it does not expect them to exist.问题是 mingw 不会查找
<libname>.a
文件,因为它不希望它们存在。
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
除了 *nix 系统上常见的普通“lib.a”约定之外,MinGW 还支持根据“.lib”和“.dll”约定命名的库
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
).这是因为 windows 不像 *nix 那样使用其库的
lib
前缀(在libfoo.so
上,共享库 foo 将是foo.dll
)。* 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
)我不确定你是如何设法让
.a
缺少lib
前缀(除非你重命名它),但是你的.a
文件中应该有一个lib
前缀(指定这个时你省略了lib
部分,所以libfoo.a
变成-lfoo
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.