且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 MinGW 静态库 (.a) 到 Visual Studio 静态库 (.lib)

更新时间:2023-11-13 19:02:52

使用 MinGW 生成的静态库存档通常与 Visual C++ 编译器/链接器兼容.因此,您应该能够通过将 .a 文件添加到 Visual Studio 项目属性中的链接器输入来直接使用它们:

The archives of static libraries generated with MinGW are generally compatible with Visual C++ compiler/linker. So, you should be able to use them directly by adding .a files to linker input in your project properties in Visual Studio:

  1. 转到项目Properties (Alt-F7).
  2. 在左侧框中,打开Configuration Properties->Linker->Input
  3. 添加您需要使用的所有 .a 档案的列表
  4. 您可能还需要添加 MinGW 的 libgcc.a
  1. Go to project Properties (Alt-F7).
  2. On the left box, open Configuration Properties->Linker->Input
  3. Add list of all .a archives you need to use
  4. You may need to add also MinGW's libgcc.a library

此外,混合C运行时库C/C++的属性->代码生成->运行时库可能会出现问题,但这取决于您与MinGW一起使用的构建配置.有时需要链接来自 MinGW 的 libmsvcrt.a,但在许多(如果不是大多数)情况下它会导致问题.

Also, there may occur problems regarding mixed C run-time libraries properties of C/C++->Code Generation->Runtime Library, but this depends on your build configuration you use with MinGW. Sometimes it is necessary to link against libmsvcrt.a from MinGW but in many (if not most) cases it causes problems.

最后,这种混合的 MinGW 和 Visual C++ 链接通常有效,但对于 C 模块而言,它不适用于 C++,据我所知.

Finally, this mixed MinGW and Visual C++ linking generally works but for C modules and it does not work for C++, as far as I know.