49

I'm trying to use xlsLib for creating Excel spreadsheets from a C++ application.

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.

Thus: is it possible to transform the GCC static library (xlslib.a) to a Visual Studio static library file (xlslib.lib)?

4 Answers 4

38

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. 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

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.

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.

4
  • but using .a causes my .exe to not be able to debug "Debugging information can not be found".
    – onmyway133
    May 22, 2013 at 12:27
  • 3
    @onmyway133 check whether a debugging symbols is still present. You can use e.g. nm --debug-syms, and if the binary stripped, it says «no symbols».
    – Hi-Angel
    Aug 29, 2014 at 16:09
  • 1
    adding libgcc.a was important for me
    – meolic
    Apr 15, 2015 at 13:07
  • You say I can generate static library using MinGW64 and use it as a resource in an MSVC project?
    – Royi
    Apr 26, 2020 at 15:51
4

but using .a causes my .exe to not be able to debug "Debugging information can not be found". – entropy May 22 at 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""

0

Here are two resources I have found useful:

[snip, wrong link]

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

-1

As far as I know, they are the same thing. Visual Studio's .lib files are also ar archives containing object files. Did you try just renaming the file? :)

2
  • 7
    No, it's not that simple, the format of the actual archive is slightly different.
    – laura
    Jan 19, 2010 at 19:52
  • I believe there is also a tool lib.exe that comes with visual studio. Using a .def file you can convert the .a to .lib.
    – jiggunjer
    Oct 19, 2015 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.