Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. LibXXX.a and XXX.lib: how to generate both, and how are they different/same?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 15.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    floatingWoods
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • F Offline
        F Offline
        floatingWoods
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          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 :-)

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • F Offline
            F Offline
            floatingWoods
            wrote on last edited by
            #5

            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)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              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.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • F Offline
                F Offline
                floatingWoods
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  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.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    floatingWoods
                    wrote on last edited by
                    #9

                    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?

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #10

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

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved