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. Creating and using DLLs with the MSVC compiler in Qt Creator
Qt 6.11 is out! See what's new in the release blog

Creating and using DLLs with the MSVC compiler in Qt Creator

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 8.5k 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.
  • S Offline
    S Offline
    Stian Andre Olsen
    wrote on last edited by
    #1

    For some time I have been using the MinGW toolchain on Windows to create a library and an application that uses the library. Let's call them MyLibrary and MyApplication. MyLibrary.pro contains:
    @TEMPLATE = lib
    TARGET = MyLibrary@
    MyApplication.pro contains:
    @TEMPLATE = app
    TARGET = MyApplication
    LIBS += -LMyLibraryPath -lMyLibrary@
    The MinGW toolchain produces MyLibrary.dll and libMyLibrary.a and I get no errors while building the application. Today, I tried to use the MSVC toolchain after installing the Qt SDK 1.1 with Qt 4.7.3 for MSVC 2008. When building the library I get no errors but while building the application I get: LNK1104: cannot open file 'MyLibrary.lib'. The error message is understandable since building the library did not create the lib file, only the dll file. Why isn't the lib file created? Should I use a different approach when creating and using a library?

    Stian Andre Olsen

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sigrid
      wrote on last edited by
      #2

      Does importing and exporting the symbols as outlined in the following FAQ:

      "Creating a library ":http://developer.qt.nokia.com/faq/answer/when_creating_a_library_with_qt_windows_and_using_it_in_an_application_then help? See also the following link to the documentation on the same subject:

      http://doc.qt.nokia.com/4.7/sharedlibrary.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Stian Andre Olsen
        wrote on last edited by
        #3

        To be honest, I haven't tried the exporting and importing. For some reason it works perfect with MinGW without any additional export and import keywords in the source code. Maybe this is the reason it doesn't work with MSVC. If so, I think I'll stick with the MinGW toolchain for now. However, it would be nice if someone could explain to me why it works with MinGW and not with MSVC. After all, it is nice to avoid additional statements and keywords in the source code.

        Stian Andre Olsen

        1 Reply Last reply
        0
        • J Offline
          J Offline
          joonhwan
          wrote on last edited by
          #4

          Post from IPhone. google __declspec dllexport and dllimport. There should be at least one exported function , IIRC.

          joonhwan at gmail dot com

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            PLease use Q_DECL_IMPORT and Q_DECL_EXPORT in Qt. Those will not break your build on non-MSVC compilers and actually work for gcc, too.

            You will need some magic to always have the right one applied. Check e.g. https://qt.gitorious.org/qt-creator/qt-creator/blobs/master/src/libs/utils/utils_global.h for an example. You then need to make sure to define (in this case) QTCREATOR_UTILS_LIB when building the library to export the symbols and leave that define out when building against the library to import them properly.

            [EDIT: fixed link, Volker]

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #6

              The reason it works for MinGW is that gcc by default does not hide symbols in libraries. You can enable this feature even for gcc by adding:

              @
              CONFIG += hide_symbols
              @

              to your .pro file.

              The effect of the above is to add:

              @
              -fvisibility=hidden -fvisibility-inlines-hidden
              @

              as arguments to each invocation of g++.

              This will actually make your runtime startup a little quicker too since the runtime linker has less work to do (assuming you do not export absolutely everything).

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Stian Andre Olsen
                wrote on last edited by
                #7

                Thanks a lot for all the good answers. I will definitely start using Q_DECL_EXPORT and Q_DECL_IMPORT in my library.

                Stian Andre Olsen

                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