Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    Tools
    3
    8
    13728
    Loading More Posts
    • 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
      JulienMaille last edited by

      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 Reply Quote 0
      • D
        dword last edited by

        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 Reply Quote 0
        • J
          JulienMaille last edited by

          Ok thanks for the clarification.

          1 Reply Last reply Reply Quote 0
          • T
            theoriginalgri last edited by

            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 Reply Quote 0
            • J
              JulienMaille last edited by

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

              1 Reply Last reply Reply Quote 0
              • T
                theoriginalgri last edited by

                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 Reply Quote 0
                • J
                  JulienMaille last edited by

                  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 Reply Quote 0
                  • T
                    theoriginalgri last edited by

                    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 Reply Quote 0
                    • First post
                      Last post