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. Statically Link 3rd Party Library Built with CMake into Qt 5.12.11 Project Built with QMake in Qt Creator
Forum Updated to NodeBB v4.3 + New Features

Statically Link 3rd Party Library Built with CMake into Qt 5.12.11 Project Built with QMake in Qt Creator

Scheduled Pinned Locked Moved Solved General and Desktop
37 Posts 2 Posters 7.2k Views 3 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.
  • C Crag_Hack

    @SGaist I might have just gotten it to work... will confirm tomorrow but it looks pretty convincing. I added add_compile_definitions(SimpleMail2Qt5_EXPORTS) to both CMakeLists.txt's. Forgot how I arrived at this necessity I'll try to remember tomorrrow :) Thanks for the help!

    C Offline
    C Offline
    Crag_Hack
    wrote on last edited by Crag_Hack
    #23

    @SGaist I finally got the library to compile statically. I had to remove SHARED from add_library, set BUILD_SHARED_LIBS to off, and add add_compile_definitions(SimpleMail2Qt5_EXPORTS) to CMakeLists.txt.

    In the SimpleMail project we have src/smtpexports.h with:

    #if defined(SimpleMail2Qt5_EXPORTS) || defined(SimpleMail2Qt6_EXPORTS)
    #define SMTP_EXPORT Q_DECL_EXPORT
    #else
    #define SMTP_EXPORT Q_DECL_IMPORT
    #endif
    

    The Q_DECL_EXPORT seems to be essential.

    Now I get another error! Bloody hell.

    Running NMake trying to build my project that uses SimpleMail I get some of these:

    SimpleMail2Qt5.lib(emailaddress.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
    

    and a lot of these:

    SimpleMail2Qt5.lib(mimemessage.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QByteArray::QByteArray(class QByteArray const &)" (__imp_??0QByteArray@@QEAA@AEBV0@@Z) referenced in function "public: __cdecl QStringBuilder<class QByteArray,class QByteArray>::operator class QByteArray(void)const " (??B?$QStringBuilder@VQByteArray@@V1@@@QEBA?AVQByteArray@@XZ)
    

    and these:

    SimpleMail2Qt5.lib(mimepart.cpp.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl QByteArray::QByteArray(class QByteArray const &)" (__imp_??0QByteArray@@QEAA@AEBV0@@Z)
    

    I'll google these guys... do you know off the top of your head what's going on?
    Thanks

    C 1 Reply Last reply
    0
    • C Crag_Hack

      @SGaist I finally got the library to compile statically. I had to remove SHARED from add_library, set BUILD_SHARED_LIBS to off, and add add_compile_definitions(SimpleMail2Qt5_EXPORTS) to CMakeLists.txt.

      In the SimpleMail project we have src/smtpexports.h with:

      #if defined(SimpleMail2Qt5_EXPORTS) || defined(SimpleMail2Qt6_EXPORTS)
      #define SMTP_EXPORT Q_DECL_EXPORT
      #else
      #define SMTP_EXPORT Q_DECL_IMPORT
      #endif
      

      The Q_DECL_EXPORT seems to be essential.

      Now I get another error! Bloody hell.

      Running NMake trying to build my project that uses SimpleMail I get some of these:

      SimpleMail2Qt5.lib(emailaddress.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
      

      and a lot of these:

      SimpleMail2Qt5.lib(mimemessage.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QByteArray::QByteArray(class QByteArray const &)" (__imp_??0QByteArray@@QEAA@AEBV0@@Z) referenced in function "public: __cdecl QStringBuilder<class QByteArray,class QByteArray>::operator class QByteArray(void)const " (??B?$QStringBuilder@VQByteArray@@V1@@@QEBA?AVQByteArray@@XZ)
      

      and these:

      SimpleMail2Qt5.lib(mimepart.cpp.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl QByteArray::QByteArray(class QByteArray const &)" (__imp_??0QByteArray@@QEAA@AEBV0@@Z)
      

      I'll google these guys... do you know off the top of your head what's going on?
      Thanks

      C Offline
      C Offline
      Crag_Hack
      wrote on last edited by Crag_Hack
      #24

      @SGaist ( or anybody ) Making progress on this, it looks like error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' is due to symbol mismatch detected by the linker. So one part of the program uses the DLL version of the run time library and another uses static version of the run time library. See here and here.

      For those who aren't following this thread I am getting this error (and many others probably related to this) when trying to compile my project using a static build of the SimpleMail plugin:

      SimpleMail2Qt5.lib(emailaddress.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
      

      The fix should be easy, just make the library use the static run time library. I tried to do this in CMakeLists.txt using both:

      set_property(TARGET SimpleMail2Qt${QT_VERSION_MAJOR} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
      //used at the end of the CMakeLists.txt in src directory of SimpleMail project directory
      

      and

      set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
      //used at the beginning of both CMakeLists.txt files (the one in the SimpleMail root and src subdirectory of SimpleMail project)
      

      but still get the linker error. See here and here and for these CMake variables. Any idea what might be wrong? Is there another way to specify whether to use the static or dll run time library when building a project using CMake and Qt Creator?

      C 1 Reply Last reply
      0
      • C Crag_Hack

        @SGaist ( or anybody ) Making progress on this, it looks like error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' is due to symbol mismatch detected by the linker. So one part of the program uses the DLL version of the run time library and another uses static version of the run time library. See here and here.

        For those who aren't following this thread I am getting this error (and many others probably related to this) when trying to compile my project using a static build of the SimpleMail plugin:

        SimpleMail2Qt5.lib(emailaddress.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
        

        The fix should be easy, just make the library use the static run time library. I tried to do this in CMakeLists.txt using both:

        set_property(TARGET SimpleMail2Qt${QT_VERSION_MAJOR} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
        //used at the end of the CMakeLists.txt in src directory of SimpleMail project directory
        

        and

        set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
        //used at the beginning of both CMakeLists.txt files (the one in the SimpleMail root and src subdirectory of SimpleMail project)
        

        but still get the linker error. See here and here and for these CMake variables. Any idea what might be wrong? Is there another way to specify whether to use the static or dll run time library when building a project using CMake and Qt Creator?

        C Offline
        C Offline
        Crag_Hack
        wrote on last edited by
        #25

        @SGaist Hi SGaist, any idea what's causing the LNK2038 error previously mentioned? Is it not using the static run-time library for building the SimpleMail library? Shouldn't CMake set variable commands shown remedy the situation? Thanks!

        SGaistS 1 Reply Last reply
        0
        • C Crag_Hack

          @SGaist Hi SGaist, any idea what's causing the LNK2038 error previously mentioned? Is it not using the static run-time library for building the SimpleMail library? Shouldn't CMake set variable commands shown remedy the situation? Thanks!

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #26

          Might be a silly question but are you sure you are using the same version of Qt to build the library and your project ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply
          0
          • SGaistS SGaist

            Might be a silly question but are you sure you are using the same version of Qt to build the library and your project ?

            C Offline
            C Offline
            Crag_Hack
            wrote on last edited by
            #27

            @SGaist Yes they are both 5.12.11.

            SGaistS 1 Reply Last reply
            0
            • C Crag_Hack

              @SGaist Yes they are both 5.12.11.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #28

              And that is a dynamic build of Qt ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              C 1 Reply Last reply
              0
              • SGaistS SGaist

                And that is a dynamic build of Qt ?

                C Offline
                C Offline
                Crag_Hack
                wrote on last edited by Crag_Hack
                #29

                @SGaist The program is built statically but the library is built using Qt Creator so dynamic right? I tried building the library static as well but bot a bunch of errors, could try again...

                SGaistS 1 Reply Last reply
                0
                • C Crag_Hack

                  @SGaist The program is built statically but the library is built using Qt Creator so dynamic right? I tried building the library static as well but bot a bunch of errors, could try again...

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #30

                  No need to build Qt statically, I am just trying to asses the situation as I currently can't figure out why the two run times are being used. The fact that the library is static does not mean that it shall use the static runtime. All the more when using a shared build of Qt.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  C 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    No need to build Qt statically, I am just trying to asses the situation as I currently can't figure out why the two run times are being used. The fact that the library is static does not mean that it shall use the static runtime. All the more when using a shared build of Qt.

                    C Offline
                    C Offline
                    Crag_Hack
                    wrote on last edited by
                    #31

                    @SGaist Sorry I meant I tried building the library using my static build of Qt, not just building the library statically (the whole point of this thread).

                    SGaistS 1 Reply Last reply
                    0
                    • C Crag_Hack

                      @SGaist Sorry I meant I tried building the library using my static build of Qt, not just building the library statically (the whole point of this thread).

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #32

                      Then here lies the issue: your static build of Qt uses the static runtime and you are trying to build your application with a dynamic build of Qt.

                      Rebuild that library with the same version of Qt as the original application.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      C 1 Reply Last reply
                      2
                      • SGaistS SGaist

                        Then here lies the issue: your static build of Qt uses the static runtime and you are trying to build your application with a dynamic build of Qt.

                        Rebuild that library with the same version of Qt as the original application.

                        C Offline
                        C Offline
                        Crag_Hack
                        wrote on last edited by Crag_Hack
                        #33

                        @SGaist I got a little further compiling the library with Qt static. Had to turn off SimpleMail demos but who cares... Now I still get the below guys. Do these mean SimpleMail or QtSingleApplication is MD_DynamicRelease? If it's SimpleMail the author might have hard coded dynamic somewhere else in the library and I will ask him for help.

                        SimpleMail2Qt5.lib(emailaddress.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                        SimpleMail2Qt5.lib(mimemessage.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                        SimpleMail2Qt5.lib(sender.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                        SimpleMail2Qt5.lib(mimepart.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                        SimpleMail2Qt5.lib(mimecontentformatter.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                        SimpleMail2Qt5.lib(mimemultipart.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                        SimpleMail2Qt5.lib(quotedprintable.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                        

                        and a bunch of these guys:

                        LINK : warning LNK4217: symbol '??0Sender@SimpleMail@@QEAA@AEBVQString@@HW4ConnectionType@01@PEAVQObject@@@Z (public: __cdecl SimpleMail::Sender::Sender(class QString const &,int,enum SimpleMail::Sender::ConnectionType,class QObject *))' defined in 'SimpleMail2Qt5.lib(sender.cpp.obj)' is imported by 'worker.obj' in function '"private: void __cdecl Worker::sendEmails(class QList<class Job> &,class QList<class Job> &)" (?sendEmails@Worker@@AEAAXAEAV?$QList@VJob@@@@0@Z)'
                        

                        and these guys:

                        worker.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl SimpleMail::MimeText::MimeText(class QString const &)" (__imp_??0MimeText@SimpleMail@@QEAA@AEBVQString@@@Z) referenced in function "private: void __cdecl Worker::sendEmails(class QList<class Job> &,class QList<class Job> &)" (?sendEmails@Worker@@AEAAXAEAV?$QList@VJob@@@@0@Z)
                        worker.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl SimpleMail::MimeText::~MimeText(void)" (__imp_??1MimeText@SimpleMail@@UEAA@XZ) referenced in function "public: virtual void * __cdecl SimpleMail::MimeText::`scalar deleting destructor'(unsigned int)" (??_GMimeText@SimpleMail@@UEAAPEAXI@Z)
                        worker.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl SimpleMail::MimeText::setText(class QString const &)" (__imp_?setText@MimeText@SimpleMail@@QEAAXAEBVQString@@@Z) referenced in function "private: void __cdecl Worker::sendEmails(class QList<class Job> &,class QList<class Job> &)" (?sendEmails@Worker@@AEAAXAEAV?$QList@VJob@@@@0@Z)
                        
                        C 1 Reply Last reply
                        0
                        • C Crag_Hack

                          @SGaist I got a little further compiling the library with Qt static. Had to turn off SimpleMail demos but who cares... Now I still get the below guys. Do these mean SimpleMail or QtSingleApplication is MD_DynamicRelease? If it's SimpleMail the author might have hard coded dynamic somewhere else in the library and I will ask him for help.

                          SimpleMail2Qt5.lib(emailaddress.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                          SimpleMail2Qt5.lib(mimemessage.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                          SimpleMail2Qt5.lib(sender.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                          SimpleMail2Qt5.lib(mimepart.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                          SimpleMail2Qt5.lib(mimecontentformatter.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                          SimpleMail2Qt5.lib(mimemultipart.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                          SimpleMail2Qt5.lib(quotedprintable.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in qtsingleapplication.obj
                          

                          and a bunch of these guys:

                          LINK : warning LNK4217: symbol '??0Sender@SimpleMail@@QEAA@AEBVQString@@HW4ConnectionType@01@PEAVQObject@@@Z (public: __cdecl SimpleMail::Sender::Sender(class QString const &,int,enum SimpleMail::Sender::ConnectionType,class QObject *))' defined in 'SimpleMail2Qt5.lib(sender.cpp.obj)' is imported by 'worker.obj' in function '"private: void __cdecl Worker::sendEmails(class QList<class Job> &,class QList<class Job> &)" (?sendEmails@Worker@@AEAAXAEAV?$QList@VJob@@@@0@Z)'
                          

                          and these guys:

                          worker.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl SimpleMail::MimeText::MimeText(class QString const &)" (__imp_??0MimeText@SimpleMail@@QEAA@AEBVQString@@@Z) referenced in function "private: void __cdecl Worker::sendEmails(class QList<class Job> &,class QList<class Job> &)" (?sendEmails@Worker@@AEAAXAEAV?$QList@VJob@@@@0@Z)
                          worker.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl SimpleMail::MimeText::~MimeText(void)" (__imp_??1MimeText@SimpleMail@@UEAA@XZ) referenced in function "public: virtual void * __cdecl SimpleMail::MimeText::`scalar deleting destructor'(unsigned int)" (??_GMimeText@SimpleMail@@UEAAPEAXI@Z)
                          worker.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl SimpleMail::MimeText::setText(class QString const &)" (__imp_?setText@MimeText@SimpleMail@@QEAAXAEBVQString@@@Z) referenced in function "private: void __cdecl Worker::sendEmails(class QList<class Job> &,class QList<class Job> &)" (?sendEmails@Worker@@AEAAXAEAV?$QList@VJob@@@@0@Z)
                          
                          C Offline
                          C Offline
                          Crag_Hack
                          wrote on last edited by
                          #34

                          @SGaist Also I got this as well but using QMAKE_LFLAGS += /NODEFAULTLIB:MSVCRT fixed it but nothing else. Thanks!

                          LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
                          
                          C 1 Reply Last reply
                          0
                          • C Crag_Hack

                            @SGaist Also I got this as well but using QMAKE_LFLAGS += /NODEFAULTLIB:MSVCRT fixed it but nothing else. Thanks!

                            LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
                            
                            C Offline
                            C Offline
                            Crag_Hack
                            wrote on last edited by
                            #35

                            @SGaist Hi Sgaist, I made a little progress, I fixed the LNK2038 errors by adding some compiler flags to change the runtime library to static. I think the MSVC_RUNTIME_LIBRARY and CMAKE_MSVC_RUNTIME_LIBRARY variables to change compiler flags to /MT and /MTd (static flags) are for executables only. And also they require cmake_minimum_required(VERSION 3.15) and cmake_policy(SET CMP0091 NEW). So I used set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") and set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") instead at the very end of the CMakeLists.txt so they override any previous setting of the compiler flags being set to something other than /MT and /MTd. These flags set the runtime library to be static.

                            However I have been unable to fix the LNK4217 and LNK2019 guys. It looks like for a static library I need to remove the __declspec(dllimport) and __declspec(dllexport) macros and replace with nothing. So in the case of SimpleMail it uses the following code in the smtpexports.h file, Q_DECL_EXPORT and Q_DECL_IMPORT being the Qt equivalent of the __declspec guys.

                            #if defined(SimpleMail2Qt5_EXPORTS)
                            #define SMTP_EXPORT Q_DECL_EXPORT
                            #else
                            #define SMTP_EXPORT Q_DECL_IMPORT
                            #endif
                            

                            I simply replaced it with this code for brevity just to test things out:

                            #if defined(SimpleMail2Qt5_EXPORTS)
                            #define SMTP_EXPORT
                            #else
                            #define SMTP_EXPORT
                            #endif
                            

                            The library ended up being a different size but still gave the LNK4217 and LNK2019 errors.

                            Any idea why it's not working?
                            Thanks

                            C 1 Reply Last reply
                            0
                            • C Crag_Hack

                              @SGaist Hi Sgaist, I made a little progress, I fixed the LNK2038 errors by adding some compiler flags to change the runtime library to static. I think the MSVC_RUNTIME_LIBRARY and CMAKE_MSVC_RUNTIME_LIBRARY variables to change compiler flags to /MT and /MTd (static flags) are for executables only. And also they require cmake_minimum_required(VERSION 3.15) and cmake_policy(SET CMP0091 NEW). So I used set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") and set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") instead at the very end of the CMakeLists.txt so they override any previous setting of the compiler flags being set to something other than /MT and /MTd. These flags set the runtime library to be static.

                              However I have been unable to fix the LNK4217 and LNK2019 guys. It looks like for a static library I need to remove the __declspec(dllimport) and __declspec(dllexport) macros and replace with nothing. So in the case of SimpleMail it uses the following code in the smtpexports.h file, Q_DECL_EXPORT and Q_DECL_IMPORT being the Qt equivalent of the __declspec guys.

                              #if defined(SimpleMail2Qt5_EXPORTS)
                              #define SMTP_EXPORT Q_DECL_EXPORT
                              #else
                              #define SMTP_EXPORT Q_DECL_IMPORT
                              #endif
                              

                              I simply replaced it with this code for brevity just to test things out:

                              #if defined(SimpleMail2Qt5_EXPORTS)
                              #define SMTP_EXPORT
                              #else
                              #define SMTP_EXPORT
                              #endif
                              

                              The library ended up being a different size but still gave the LNK4217 and LNK2019 errors.

                              Any idea why it's not working?
                              Thanks

                              C Offline
                              C Offline
                              Crag_Hack
                              wrote on last edited by
                              #36

                              @SGaist I can be a little flaky sometimes... was using a different computer to compile the library than that which I was compiling my program. DUH! I'll post an answer with everything I did later. Thanks SGaist!

                              C 1 Reply Last reply
                              0
                              • C Crag_Hack

                                @SGaist I can be a little flaky sometimes... was using a different computer to compile the library than that which I was compiling my program. DUH! I'll post an answer with everything I did later. Thanks SGaist!

                                C Offline
                                C Offline
                                Crag_Hack
                                wrote on last edited by Crag_Hack
                                #37

                                Here is what I had to do to compile the SimpleMail library statically:

                                1. Load SimpleMail into Qt Creator by opening CMakeLists.txt from the SimpleMail directory
                                2. In Qt Creator set the BUILD_SHARED_LIBS option to OFF in Project settings for SimpleMail (see post 6)
                                3. Remove SHARED from the end of the add_library(SimpleMail2Qt${QT_VERSION_MAJOR} command in CMakeLists.txt in the src subdir (it will then default to SHARED or STATIC based on the BUILD_SHARED_LIBS setting)
                                4. Add the following commands to the end of CMakeLists.txt in the src subdir (at the end so they override any previous compiler flags set)
                                  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
                                  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

                                  These tell CMake to use the static version of the MSVC run-time library.
                                5. Turn off demo compilation with option(BUILD_DEMOS "Build the demos" OFF)
                                6. SimpleMail was not configured to support static build by default so I had to change some code in smtpexports.h to change functions from being linked for DLL usage to static usage:
                                  #define SMTP_EXPORT
                                  /#if defined(SimpleMail2Qt5_EXPORTS)
                                  #define SMTP_EXPORT Q_DECL_EXPORT
                                  #else
                                  #define SMTP_EXPORT Q_DECL_IMPORT
                                  #endif
                                  /

                                  For any library that is not built for static builds by default like SimpleMail you have to do the same. Q_DECL_EXPORT and Q_DECL_IMPORT are Qt macros for __declspec(dllexport) and __declspec(dllimport) respectively so if your library uses those you'll have to do the same for those guys in the library. By doing a #define for the macro without a value it will be empty and therefore avoid adding those __declspec guys to the library.
                                7. Make sure to build the library using a static build of Qt.
                                1 Reply Last reply
                                0
                                • C Crag_Hack has marked this topic as solved on

                                • Login

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