简体   繁体   English

g++ 只查找.lib 文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM