visual-studio 从 MinGW 静态库 (.a) 到 Visual Studio 静态库 (.lib)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2096519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
From MinGW static library (.a) to Visual Studio static library (.lib)
提问by user254336
I'm trying to use xlsLibfor creating Excel spreadsheets from a C++ application.
我正在尝试使用xlsLib从 C++ 应用程序创建 Excel 电子表格。
The trouble is that compiling xlsLib, I give a .a file (a GCC static library, generated by MinGW). But, my application depends on another API (PhysX) that only compiles with Visual Studio.
麻烦的是,编译xlsLib,我给了一个.a文件(一个GCC静态库,由MinGW生成)。但是,我的应用程序依赖于另一个PhysX只能使用 Visual Studio 编译的API ( )。
Thus: is it possible to transform the GCC static library (xlslib.a) to a Visual Studio static library file (xlslib.lib)?
因此:是否可以将 GCC 静态库 ( xlslib.a) 转换为 Visual Studio 静态库文件 ( xlslib.lib)?
回答by mloskot
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 .afiles to linker input in your project properties in Visual Studio:
使用 MinGW 生成的静态库档案通常与 Visual C++ 编译器/链接器兼容。因此,您应该能够通过将.a文件添加到 Visual Studio 项目属性中的链接器输入来直接使用它们:
- Go to project
Properties(Alt-F7). - On the left box, open
Configuration Properties->Linker->Input - Add list of all
.aarchives you need to use - You may need to add also MinGW's
libgcc.alibrary
- 转到项目
Properties(Alt-F7)。 - 在左侧的框中,打开
Configuration Properties->Linker->Input - 添加
.a您需要使用的所有档案的列表 - 您可能还需要添加 MinGW 的
libgcc.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.afrom MinGW but in many (if not most) cases it causes problems.
此外,混合 C 运行时库可能会出现问题properties of C/C++->Code Generation->Runtime Library,但这取决于您与 MinGW 一起使用的构建配置。有时需要libmsvcrt.a从 MinGW链接,但在许多(如果不是大多数)情况下它会导致问题。
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.
最后,据我所知,这种混合的 MinGW 和 Visual C++ 链接通常适用于 C 模块,但不适用于 C++。
回答by gnaggnoyil
but using .a causes my .exe to not be able to debug "Debugging information can not be found". – entropy May 22 at 12:27
但是使用 .a 会导致我的 .exe 无法调试“找不到调试信息”。– 熵 5 月 22 日 12:27
that's because the .a library does not include the debug info necessary for debugging. you need to tell the compiler to add debug info when in compilation if you want to debug it. for mingw, you need to add "-g" to CFLAGS when you run "make", like "make CFLAGS="-g""
那是因为 .a 库不包含调试所需的调试信息。如果你想调试它,你需要告诉编译器在编译时添加调试信息。对于 mingw,您需要-g在运行“ make”时将“ ”添加到 CFLAGS ,例如“ make CFLAGS="-g"”
回答by laura
Here are two resources I have found useful:
以下是我发现有用的两个资源:
[snip, wrong link]
[截图,错误链接]
http://old.nabble.com/using-VC%2B%2B-.lib-with-mingw-td23151303.html
http://old.nabble.com/using-VC%2B%2B-.lib-with-mingw-td23151303.html
Edit. I can't find the link I was looking for. In the meanwhile, check this one out: http://www.willus.com/mingw/yongweiwu_stdcall.html
编辑。我找不到我要找的链接。同时,看看这个:http: //www.willus.com/mingw/yongweiwu_stdcall.html
回答by Nicolás
As far as I know, they are the same thing. Visual Studio's .libfiles are also ararchives containing object files. Did you try just renaming the file? :)
据我所知,它们是同一回事。Visual Studio 的.lib文件也是ar包含目标文件的档案。您是否尝试仅重命名文件?:)

