Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [solved] qmake: build a dll and its .lib for MSVC
QtWS25 Last Chance

[solved] qmake: build a dll and its .lib for MSVC

Scheduled Pinned Locked Moved Qt Creator and other tools
8 Posts 3 Posters 14.5k Views
  • 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Dear QT gurus, I'm trying to build (with msvc) a dynamic library and would like to import it in another project compiled with Microsoft Visual C++ too.
    @TEMPLATE = lib
    CONFIG += dll
    TARGET = mylib
    VERSION = 1.0@
    I searched across different forums and did find that I should add QMAKE_LFLAGS += /IMPLIB:mylib.lib my .pro file.
    People say that it just need the /implib switch to be present in the link command line of the MSVC project.

    Could someone confirm that I am doing this right?
    Thanks a lot.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dword
      wrote on last edited by
      #2

      Hi neFAST,
      Doing juste /implib generate a bad command line for the linker (at least not usable since it creates a file name 'u' or something like that). Specifying the export lib name: QMAKE_LFLAGS += /IMPLIB:mylib.lib works fine.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        Ok thanks for the clarification.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          theoriginalgri
          wrote on last edited by
          #4

          Erm ... huh?

          Isn't the most portable way the default one? With QMake there's no difference when linking libraries/dlls with gcc or msvc.

          Just adding a new lib directory with
          @LIBS += -L../myfancydll/debug@

          and linking it with
          @LIBS += -lmyfancydll@

          ??

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #5

            With LIBS you specify the libraries that your project will link against.
            This is not what I wanted to do.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              theoriginalgri
              wrote on last edited by
              #6

              I just read the description
              [quote author="neFAST" date="1303579517"]Dear QT gurus, I'm trying to build (with msvc) a dynamic library and would like to import it in another project compiled with Microsoft Visual C++ too.[/quote]

              And there the "normal way" is in the dynamic library:
              Doing exports by defining a MYFANCYDLL_EXPORTS which defines MYFANCYDLL_API to either __declspec(dllimport) or __declspec(dllexport).

              And linking this one in the application which is using the dynamic lib with:
              LIBS += -LC:\mysources\myfancydll -lmyfancydll

              If you're doing something special I may have misunderstood your question. I've never needed the /implib thing for anything :)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JulienMaille
                wrote on last edited by
                #7

                Ok maybe the sentence was not clear (but dword undestood)
                Ok I want to import this lib in another project, and I already know how to do that.
                But I need to export it first when building the dll.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  theoriginalgri
                  wrote on last edited by
                  #8

                  Ok, but you know how the symbols are exported?

                  ---- If you don't know: ----
                  In the dll project, create a "exports.h" (or call it whatever you like)
                  It should have the following contents:
                  @#ifdef MYFANCYDLL_EXPORTS

                  define MYFANCYDLL_API __declspec(dllexport)

                  #else

                  define MYFANCYDLL_API __declspec(dllimport)

                  #endif@

                  In your myfancydll.pro, add
                  @DEFINES += MYFANCYDLL_EXPORTS@

                  Every class which should be exported should be written like the following:
                  @#include "exports.h"

                  class MYFANCYDLL_API MyExportedClass
                  {
                  public:
                  void someFunction();
                  }@

                  When writing this way, a .lib file will be generated automatically, there's also no need for creating a .def file. By the way: Qt does the linkage the same way, see the Q_GUI_EXPORT in every QtGui class definition.

                  If you already know this stuff, just ignore this reply :)

                  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