LibXXX.a and XXX.lib: how to generate both, and how are they different/same?



  • Hello,

    I use QtCreator under Windows and compile sometimes with Mingw, othertimes with MSVC2005. The application is a library and generates a dll. With the first compiler it produces a libXXX.a lib-file, with the second a XXX.lib file. While I am familiar with the ".lib" files, I am wondering how different the ".a" file is. Logically, both should be usable in a same way, no? Which one should I distribute if someone wants to statically link to my library? And is there a configuration instruction that allows generating both at the same time?

    Thanks for any insight



  • You should distribute the lib file for the respective toolchain, i.e. either the MSVC generated files or those of MinGW.

    For Visual Studio you have:

    • xxx.dll
      the library containing the actual object code, it must be deployed to any target machine
    • xxx.lib
      a fake library that provides some glue to make the linker happy, you need to provide this to a developer who links to your library

    For MinGW you have the same functionality in

    • libxxx.dll
    • libxxx.dll.a

    In bigger projects, the DLLs are usually placed in a bin directory, as they are needed by the applications on runtime. The .lib/.dll.a are usually in a lib directory, as they are only needed by developers.

    For static libraries you only have xxx.lib on MSVS and libxxx.a on MinGW.

    Basically they contain the same stuff - in the sense of being built from the same source code. You must not interchange C++ libs between Visual Studio and MinGW, as the ABI and name mangling is not compatible.

    The easy part is: You need not care about the actual naming as the build system (compiler etc.) takes care of translating to real file names when addig something like this to your link list:

    @
    LIBS += -lxxx
    @



  • Thanks a lot Volker for the elaborate reply, again!

    I see, so I will have to distribute the libxxx.dll and libxxx.a files. But: will peole be able to use that library when writing an application that compiles with MSVC? I mean I've never seen any MSVC application specifying a ".a"-file



  • No. For developers using MSVC, you need to distribute the .dll and .lib. The object files of MinGW and MSVC are not interchangeable in general (some exceptions apply to pure C libs). You will have to build your lib using MSVC in that case. And don't forget to include the header files, of course :-)



  • Actually my library functions are pure C. Does that make a difference? I mean the library is written in c++, but the interface is kept in C.

    From my Qt, Mingw-compiled library, I am also linking to some MSVC-compiled libraries, and it works fine it seems (there again, the interface is pure C)



  • I don't know whether that's possible. I would say that the C++ based libs will need a C++ stdlib etc. Which would be that of MinGW, as the MSVC one isn't compatible. You will have to try yourself. I would regard this setup as experimental, even if it kind of works, though.



  • Thanks again Volker.
    But what about libraries like gl.lib and such? I never had to adjust for any specific library regardless of the used compiler. And so I thought that all use the same xxx.lib, xxx.h and xxx.dll files...



  • In case the library consists of pure C code, it should work. As soon as C++ is involved, I would say it's problematic at best.



  • Thanks again Volker.
    If I late bind the library (i.e. use LoadLibrary/GetProcAddress) then it should work fine in any situation, given that I only import pure C-functions, right?



  • Using pure C functions, this should work. I would recommend to test it with a simple, minimal test project, just to be 100% sure.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.