Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Building DLL in Visual Studio with Static Linking to QT

Building DLL in Visual Studio with Static Linking to QT

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
visual studiovisual c++staticstatic linkingdll
17 Posts 3 Posters 9.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.
  • K koahnig
    12 Jun 2017, 18:46

    @mlathrop

    You are aware of the implications with respect to licenses?

    Do you have QByteArray in the library?

    M Offline
    M Offline
    mlathrop
    wrote on 12 Jun 2017, 20:50 last edited by
    #3

    @koahnig Yes I have a startup licence. QString is used in the DLL and so is toLocal8Bit(). What do you mean by is it "in" the library? Do you mean is it used? Or is it included? Or something else?

    K 1 Reply Last reply 12 Jun 2017, 21:25
    0
    • M mlathrop
      12 Jun 2017, 20:50

      @koahnig Yes I have a startup licence. QString is used in the DLL and so is toLocal8Bit(). What do you mean by is it "in" the library? Do you mean is it used? Or is it included? Or something else?

      K Offline
      K Offline
      koahnig
      wrote on 12 Jun 2017, 21:25 last edited by
      #4

      @mlathrop

      You are creating a dll and I refered to this as a library as short for dynamic link library.
      It looks like you have hand-picked some of the class. You need to take of all the dependencies and QString and QByteArray have dependencies as you see in the documentation.
      Therefore the question, if you have included QByteArray in your dll. If not, this would explain your error message.

      When you are entitled to get support, why are not asking there?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mlathrop
        wrote on 19 Jun 2017, 20:35 last edited by
        #5

        @koahnig
        Sorry for the delay in responding... I can't seem to get this to email me when people post. First off, the startup license doesn't have support :/

        On the actual issue:
        I have tried to just build dynamically for the sake of a more common case, and I get the same error. I am linking the client application to qtmain.lib and Qt5Core.lib as well. In the cpp file of the DLL I have the following includes:
        #include <QString>
        #include <QFile>
        #include <QXmlStreamWriter>
        #include <QXmlStreamReader>
        #include <QByteArray>

        I am curious as to why I don't get any kind of error at Link or compile time for the DLL.

        K K 2 Replies Last reply 19 Jun 2017, 21:24
        0
        • M mlathrop
          19 Jun 2017, 20:35

          @koahnig
          Sorry for the delay in responding... I can't seem to get this to email me when people post. First off, the startup license doesn't have support :/

          On the actual issue:
          I have tried to just build dynamically for the sake of a more common case, and I get the same error. I am linking the client application to qtmain.lib and Qt5Core.lib as well. In the cpp file of the DLL I have the following includes:
          #include <QString>
          #include <QFile>
          #include <QXmlStreamWriter>
          #include <QXmlStreamReader>
          #include <QByteArray>

          I am curious as to why I don't get any kind of error at Link or compile time for the DLL.

          K Offline
          K Offline
          koahnig
          wrote on 19 Jun 2017, 21:24 last edited by
          #6

          @mlathrop

          Are you always using the same VS compiler? You cannot mixed with different version of the MS compiler. AFAIK only the 2017 studio is compatible with the previous version.
          Therefore, the best is you download the pre-compiled library for the same version of visual studio. Otherwise you may error messages as you posted.

          Vote the answer(s) that helped you to solve your issue(s)

          M 1 Reply Last reply 21 Jun 2017, 17:59
          1
          • M mlathrop
            19 Jun 2017, 20:35

            @koahnig
            Sorry for the delay in responding... I can't seem to get this to email me when people post. First off, the startup license doesn't have support :/

            On the actual issue:
            I have tried to just build dynamically for the sake of a more common case, and I get the same error. I am linking the client application to qtmain.lib and Qt5Core.lib as well. In the cpp file of the DLL I have the following includes:
            #include <QString>
            #include <QFile>
            #include <QXmlStreamWriter>
            #include <QXmlStreamReader>
            #include <QByteArray>

            I am curious as to why I don't get any kind of error at Link or compile time for the DLL.

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 19 Jun 2017, 21:45 last edited by
            #7

            Wait a bit. This symbol looks very strange. There is no Qstring::toLocal8Bit the class is QString!

            Read and abide by the Qt Code of Conduct

            K 1 Reply Last reply 20 Jun 2017, 07:38
            1
            • K kshegunov
              19 Jun 2017, 21:45

              Wait a bit. This symbol looks very strange. There is no Qstring::toLocal8Bit the class is QString!

              K Offline
              K Offline
              koahnig
              wrote on 20 Jun 2017, 07:38 last edited by
              #8

              @kshegunov

              What is about this toLocal8Bit? This is in QString. Do you mean QByteArray?
              I do not know the syntax of VC compilers.

              Vote the answer(s) that helped you to solve your issue(s)

              K 1 Reply Last reply 20 Jun 2017, 08:17
              1
              • K koahnig
                20 Jun 2017, 07:38

                @kshegunov

                What is about this toLocal8Bit? This is in QString. Do you mean QByteArray?
                I do not know the syntax of VC compilers.

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 20 Jun 2017, 08:17 last edited by kshegunov
                #9

                ?toLocal8Bit@Qstring@ is the (qualified) symbol name, Qstring::toLocal8Bit in this case.
                @ is the end of symbol name (a separator).
                QEGBA is the methods characteristic - CV-qualifier, access (public/private/protected), calling convention etc.
                ?AVQByteArray@ is the qualified name of the return type - class QByteArray.
                @ is the end of section (a separator).
                XZ - basically means "no method parameters".

                So the above (if I haven't made a mistake) should be:

                public: QByteArray __thiscall Qstring::toLocal8Bit() const;
                

                Now, see that the class is wrong, there's no Qstring in Qt, the name should be capitalized.

                Read and abide by the Qt Code of Conduct

                K 1 Reply Last reply 20 Jun 2017, 08:37
                1
                • K kshegunov
                  20 Jun 2017, 08:17

                  ?toLocal8Bit@Qstring@ is the (qualified) symbol name, Qstring::toLocal8Bit in this case.
                  @ is the end of symbol name (a separator).
                  QEGBA is the methods characteristic - CV-qualifier, access (public/private/protected), calling convention etc.
                  ?AVQByteArray@ is the qualified name of the return type - class QByteArray.
                  @ is the end of section (a separator).
                  XZ - basically means "no method parameters".

                  So the above (if I haven't made a mistake) should be:

                  public: QByteArray __thiscall Qstring::toLocal8Bit() const;
                  

                  Now, see that the class is wrong, there's no Qstring in Qt, the name should be capitalized.

                  K Offline
                  K Offline
                  koahnig
                  wrote on 20 Jun 2017, 08:37 last edited by
                  #10

                  @kshegunov

                  Sorry, I did not catch the lower case 's'.

                  However, when it is a typing error in user's code, it shall be caught by the compiler or there is also the same typing error in include file. All very strange.

                  Vote the answer(s) that helped you to solve your issue(s)

                  K 1 Reply Last reply 20 Jun 2017, 08:39
                  2
                  • K koahnig
                    20 Jun 2017, 08:37

                    @kshegunov

                    Sorry, I did not catch the lower case 's'.

                    However, when it is a typing error in user's code, it shall be caught by the compiler or there is also the same typing error in include file. All very strange.

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 20 Jun 2017, 08:39 last edited by
                    #11

                    @koahnig said in Building DLL in Visual Studio with Static Linking to QT:

                    when it is a typing error in user's code, it shall be caught by the compiler or there is also the same typing error in include file.

                    Yes, my point exactly!

                    All very strange.

                    Indeed, something's fishy here.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    2
                    • K koahnig
                      19 Jun 2017, 21:24

                      @mlathrop

                      Are you always using the same VS compiler? You cannot mixed with different version of the MS compiler. AFAIK only the 2017 studio is compatible with the previous version.
                      Therefore, the best is you download the pre-compiled library for the same version of visual studio. Otherwise you may error messages as you posted.

                      M Offline
                      M Offline
                      mlathrop
                      wrote on 21 Jun 2017, 17:59 last edited by mlathrop
                      #12

                      @koahnig
                      I am using 2015 across the board so I don't think that is the issue... Interestingly, things don't work when I build dynamically and link against the QT libraries either. The capitalization error was a typo when I re-typed the error message (it is shown on a pop-up window that I couldn't copy from). The post it edited to reflect this. A workaround for the issue is to call "name.toStdString().c_str()" where name is the QString, though this feels less efficient.

                      K K 2 Replies Last reply 21 Jun 2017, 19:08
                      0
                      • M mlathrop
                        21 Jun 2017, 17:59

                        @koahnig
                        I am using 2015 across the board so I don't think that is the issue... Interestingly, things don't work when I build dynamically and link against the QT libraries either. The capitalization error was a typo when I re-typed the error message (it is shown on a pop-up window that I couldn't copy from). The post it edited to reflect this. A workaround for the issue is to call "name.toStdString().c_str()" where name is the QString, though this feels less efficient.

                        K Offline
                        K Offline
                        koahnig
                        wrote on 21 Jun 2017, 19:08 last edited by
                        #13

                        @mlathrop

                        Really a bit strange. Possibly you should post a snippet of your code showing where the problem shows up.

                        When you are using dlls is this self-compiled or pre-build from Qt webpage?

                        Also when you compile, from where do you take the code?
                        At least in the past there was always the recommendation to download the source code archive (.zip for windows). The source code as delivered with the pre-compiled Qt libs was not suitable for re-compilation. AFAIK this is still the case or at least I have not read the opposite yet.

                        Vote the answer(s) that helped you to solve your issue(s)

                        M 1 Reply Last reply 21 Jun 2017, 21:14
                        0
                        • K koahnig
                          21 Jun 2017, 19:08

                          @mlathrop

                          Really a bit strange. Possibly you should post a snippet of your code showing where the problem shows up.

                          When you are using dlls is this self-compiled or pre-build from Qt webpage?

                          Also when you compile, from where do you take the code?
                          At least in the past there was always the recommendation to download the source code archive (.zip for windows). The source code as delivered with the pre-compiled Qt libs was not suitable for re-compilation. AFAIK this is still the case or at least I have not read the opposite yet.

                          M Offline
                          M Offline
                          mlathrop
                          wrote on 21 Jun 2017, 21:14 last edited by
                          #14

                          @koahnig said in Building DLL in Visual Studio with Static Linking to QT:

                          east in the past there was always the recommendation to download the source code archive (.zip for windows). The source code as delivered with the pre-compiled Qt libs was not suitable for re-compilation. AFAIK this is still the case or at least I have not read the

                          I got the dll's from the website (or actually from the installer... but all it does is download them...)

                          Here is a code snippet:

                          if (xml.isEndElement() && xml.name() == "Test") {
                                    int id = Add(left, right, bottom, top, front, back);
                                    QString adjusted_name = name;
                                    int i = 0;
                                    while (!SetName(id, adjusted_name.toLocal8Bit())) {
                                      adjusted_name = name + QString::number(i++);
                                    }
                          }
                          
                          K 1 Reply Last reply 22 Jun 2017, 06:53
                          0
                          • M mlathrop
                            21 Jun 2017, 21:14

                            @koahnig said in Building DLL in Visual Studio with Static Linking to QT:

                            east in the past there was always the recommendation to download the source code archive (.zip for windows). The source code as delivered with the pre-compiled Qt libs was not suitable for re-compilation. AFAIK this is still the case or at least I have not read the

                            I got the dll's from the website (or actually from the installer... but all it does is download them...)

                            Here is a code snippet:

                            if (xml.isEndElement() && xml.name() == "Test") {
                                      int id = Add(left, right, bottom, top, front, back);
                                      QString adjusted_name = name;
                                      int i = 0;
                                      while (!SetName(id, adjusted_name.toLocal8Bit())) {
                                        adjusted_name = name + QString::number(i++);
                                      }
                            }
                            
                            K Offline
                            K Offline
                            koahnig
                            wrote on 22 Jun 2017, 06:53 last edited by
                            #15

                            @mlathrop said in Building DLL in Visual Studio with Static Linking to QT:

                            @koahnig said in Building DLL in Visual Studio with Static Linking to QT:

                            east in the past there was always the recommendation to download the source code archive (.zip for windows). The source code as delivered with the pre-compiled Qt libs was not suitable for re-compilation. AFAIK this is still the case or at least I have not read the

                            I got the dll's from the website (or actually from the installer... but all it does is download them...)

                            This means that you standard pre-compiled dll version. When you have taken care of chosing the same pre-compiled version as the tool chain you are using, this should be fine.

                            Are you mixing std::string with QString?
                            When name is std::string than you a conversion.

                            What is the parameter in SetName?
                            There may apply the same.

                            Vote the answer(s) that helped you to solve your issue(s)

                            M 1 Reply Last reply 22 Jun 2017, 21:59
                            0
                            • M mlathrop
                              21 Jun 2017, 17:59

                              @koahnig
                              I am using 2015 across the board so I don't think that is the issue... Interestingly, things don't work when I build dynamically and link against the QT libraries either. The capitalization error was a typo when I re-typed the error message (it is shown on a pop-up window that I couldn't copy from). The post it edited to reflect this. A workaround for the issue is to call "name.toStdString().c_str()" where name is the QString, though this feels less efficient.

                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 22 Jun 2017, 07:27 last edited by kshegunov
                              #16

                              @mlathrop said in Building DLL in Visual Studio with Static Linking to QT:

                              Interestingly, things don't work when I build dynamically and link against the QT libraries either.

                              Then it's most probably a linking issue. Can you show how you link the Qt libraries (e.g. from your .pro file)? Also add the actual linker invocation line, so we can see what is executed exactly.

                              A workaround for the issue is to call "name.toStdString().c_str()" where name is the QString, though this feels less efficient.

                              Besides inefficient, depending on how you use that it might be much less safe ...

                              Read and abide by the Qt Code of Conduct

                              1 Reply Last reply
                              1
                              • K koahnig
                                22 Jun 2017, 06:53

                                @mlathrop said in Building DLL in Visual Studio with Static Linking to QT:

                                @koahnig said in Building DLL in Visual Studio with Static Linking to QT:

                                east in the past there was always the recommendation to download the source code archive (.zip for windows). The source code as delivered with the pre-compiled Qt libs was not suitable for re-compilation. AFAIK this is still the case or at least I have not read the

                                I got the dll's from the website (or actually from the installer... but all it does is download them...)

                                This means that you standard pre-compiled dll version. When you have taken care of chosing the same pre-compiled version as the tool chain you are using, this should be fine.

                                Are you mixing std::string with QString?
                                When name is std::string than you a conversion.

                                What is the parameter in SetName?
                                There may apply the same.

                                M Offline
                                M Offline
                                mlathrop
                                wrote on 22 Jun 2017, 21:59 last edited by
                                #17

                                @koahnig

                                SetName takes in a char* because it is a part of an API.

                                @kshegunov

                                Here are the relevant linker calls. I don't know how to get the .pro file from a VS project.

                                Here is the linker call in the project that makes the dll:

                                /OUT:"E:\Users\misappsci\Documents\Projects\yyy\x64\bin\yyy3D.dll" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"E:\Users\misappsci\Documents\Projects\yyy\x64\bin\yyy3D.pdb" /DYNAMICBASE "sl_zed64.lib" "opencv_world310.lib" "cudart.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "qtmain.lib" "Qt5Core.lib" "Qt5Multimedia.lib" "Qt5Gui.lib" "winmm.lib" /IMPLIB:"E:\Users\misappsci\Documents\Projects\yyy\x64\bin\yyy3D.lib" /DEBUG /DLL /MACHINE:X64 /OPT:REF /PGD:"E:\Users\misappsci\Documents\Projects\yyy\x64\bin\yyy3D.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\3DRelease\yyy3D.dll.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64" /LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0/lib/x64" /LIBPATH:"C:\Program Files (x86)\ZED SDK\dependencies\opencv_3.1.0/x64/vc14/lib" /LIBPATH:"C:\Program Files (x86)\ZED SDK\lib" /LIBPATH:"C:\Program Files\boost\boost_1_63_0/lib/x64" /LIBPATH:"C:\Qt\5.7\msvc2015_64\lib" /TLBID:1 
                                

                                Here is the linker call for the project that uses the dll and has the run time error:

                                /OUT:"E:\Users\misappsci\Documents\Projects\Aerie\host_x64\x64\Release\AerieLib.dll" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"E:\Users\misappsci\Documents\Projects\Aerie\host_x64\x64\Release\AerieLib.pdb" /DYNAMICBASE "Qt5Core.lib" "Qt5Gui.lib" "Qt5Multimedia.lib" "yyy3D.lib" "sl_zed64.lib" "opencv_world310.lib" "cudart.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"E:\Users\misappsci\Documents\Projects\Aerie\host_x64\x64\Release\AerieLib.lib" /DEBUG /DLL /MACHINE:X64 /OPT:REF /PGD:"E:\Users\misappsci\Documents\Projects\Aerie\host_x64\x64\Release\AerieLib.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\AerieLib.dll.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Qt\5.7\msvc2015_64\lib" /LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0/lib/x64" /LIBPATH:"C:\Program Files (x86)\ZED SDK\dependencies\opencv_3.1.0/x64/vc14/lib" /LIBPATH:"C:\Program Files (x86)\ZED SDK\lib" /LIBPATH:"E:\Users\misappsci\Documents\Projects\yyy\x64\bin" /LIBPATH:"C:\Program Files\boost\boost_1_63_0/lib/x64/" /TLBID:1 
                                
                                1 Reply Last reply
                                0

                                12/17

                                21 Jun 2017, 17:59

                                • Login

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