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. Static version does not include external targetted libs
QtWS25 Last Chance

Static version does not include external targetted libs

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
12 Posts 4 Posters 733 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.
  • S Offline
    S Offline
    shokarta
    wrote on last edited by shokarta
    #1

    Hello gurus,

    so I use static version,
    all works fine, app exe is generated with all standard and qt dlls so its fine to open in any windows machine.

    However the external libraries i link against the project are NOT included in this...

    cmake:

    ...
    set_target_properties(${PROJECT} PROPERTIES
        WIN32_EXECUTABLE TRUE
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/nwrfcsdk/include"
    )
    ...
    set(SAPNWRFC_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/nwrfcsdk/lib")
    if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
        set(SAPNWRFC_LIB_FILES sapnwrfc.lib libsapucum.lib)
    else()
        set(SAPNWRFC_LIB_FILES -lsapnwrfc -lsapucum)
    endif()
    target_link_directories(${PROJECT} PRIVATE ${SAPNWRFC_LIB_DIR})
    ...
    target_link_libraries(${PROJECT}
        PRIVATE Qt6::Quick
        PRIVATE Qt6::Gui
        PRIVATE ${SAPNWRFC_LIB_FILES}
    )
    ...
    install(TARGETS ${PROJECT}
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
    

    of course on my pc all works fine as i have this include folder set in PATH variable, however on another PC where these libraries are missing the app does not work

    do i somehow need those libs (dlls) which i target/include against the project also set to be staticaly build in the project?

    jsulmJ 1 Reply Last reply
    0
    • S shokarta

      Hello gurus,

      so I use static version,
      all works fine, app exe is generated with all standard and qt dlls so its fine to open in any windows machine.

      However the external libraries i link against the project are NOT included in this...

      cmake:

      ...
      set_target_properties(${PROJECT} PROPERTIES
          WIN32_EXECUTABLE TRUE
          INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/nwrfcsdk/include"
      )
      ...
      set(SAPNWRFC_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/nwrfcsdk/lib")
      if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
          set(SAPNWRFC_LIB_FILES sapnwrfc.lib libsapucum.lib)
      else()
          set(SAPNWRFC_LIB_FILES -lsapnwrfc -lsapucum)
      endif()
      target_link_directories(${PROJECT} PRIVATE ${SAPNWRFC_LIB_DIR})
      ...
      target_link_libraries(${PROJECT}
          PRIVATE Qt6::Quick
          PRIVATE Qt6::Gui
          PRIVATE ${SAPNWRFC_LIB_FILES}
      )
      ...
      install(TARGETS ${PROJECT}
          BUNDLE DESTINATION .
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
      

      of course on my pc all works fine as i have this include folder set in PATH variable, however on another PC where these libraries are missing the app does not work

      do i somehow need those libs (dlls) which i target/include against the project also set to be staticaly build in the project?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @shokarta said in Static version does not include external targetted libs:

      all works fine, app exe is generated with all standard and qt dlls

      I'm not sure I understand what you're writing.
      Do you mean you link your app statically against static Qt libs?
      Are those not "included" libs also static libs? Everything needs to be static if you really want to have a single exe with everything included.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • jsulmJ jsulm

        @shokarta said in Static version does not include external targetted libs:

        all works fine, app exe is generated with all standard and qt dlls

        I'm not sure I understand what you're writing.
        Do you mean you link your app statically against static Qt libs?
        Are those not "included" libs also static libs? Everything needs to be static if you really want to have a single exe with everything included.

        S Offline
        S Offline
        shokarta
        wrote on last edited by
        #3

        @jsulm all QT libs and System libs ar eincluded in the exe file...
        only those in /nwrfcsdk/lib/ are not included...

        There are bunch of *.dll files, couple *lib files and one *.pdb file,
        and in the folder /nwrfcsdk/include/ there are only *.h files,
        therefore I dont know how to find out if those libs are static as well

        jsulmJ 1 Reply Last reply
        0
        • S shokarta

          @jsulm all QT libs and System libs ar eincluded in the exe file...
          only those in /nwrfcsdk/lib/ are not included...

          There are bunch of *.dll files, couple *lib files and one *.pdb file,
          and in the folder /nwrfcsdk/include/ there are only *.h files,
          therefore I dont know how to find out if those libs are static as well

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @shokarta *.lib could be static libs (if Microsoft compiler was used), but they also can be the files needed to link against shared libs. So, I can't tell you for sure whether these libs are shared or static (but most probably shared).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            You seem to be confused and are confusing everybody else as well. You either link statically OR you have DLLs. DLLs is the part that is called dynamic linking instead of static linking.

            If you haven't compiled the Qt libraries yourself, Qt is linked dynamically and you need to provide the corresponding DLLs.

            The same goes for other libraries. If those have DLLs you need to dynamically link those. (Dynamic linking actually refers to the OS having a dynamic linker which will load the DLLs every time you launch your app exe.) Still, DLLs normally have a corresponding .lib file. The .lib file just contains all the function names provided by the DLL. The linker (the one you are using during compilation) then knows that these functions are in fact not missing, but are also not linked into the app exe. As long as you can successfully compile and link your app you most likely did everything right. Windows also has a special feature that header files can list which libraries to link so these will link automatically (the corresponding .lib file for either a DLL or a real static library).

            I am not familiar with Qt and CMake, so I am not sure what exactly install does in your CMake script. However, there is a Qt tool called windeployqt which will gather the necessary DLLs for deployment.

            S 1 Reply Last reply
            0
            • S SimonSchroeder

              You seem to be confused and are confusing everybody else as well. You either link statically OR you have DLLs. DLLs is the part that is called dynamic linking instead of static linking.

              If you haven't compiled the Qt libraries yourself, Qt is linked dynamically and you need to provide the corresponding DLLs.

              The same goes for other libraries. If those have DLLs you need to dynamically link those. (Dynamic linking actually refers to the OS having a dynamic linker which will load the DLLs every time you launch your app exe.) Still, DLLs normally have a corresponding .lib file. The .lib file just contains all the function names provided by the DLL. The linker (the one you are using during compilation) then knows that these functions are in fact not missing, but are also not linked into the app exe. As long as you can successfully compile and link your app you most likely did everything right. Windows also has a special feature that header files can list which libraries to link so these will link automatically (the corresponding .lib file for either a DLL or a real static library).

              I am not familiar with Qt and CMake, so I am not sure what exactly install does in your CMake script. However, there is a Qt tool called windeployqt which will gather the necessary DLLs for deployment.

              S Offline
              S Offline
              shokarta
              wrote on last edited by
              #6

              @SimonSchroeder Thank you for quite well corresponding explanation!

              tho from your reply, I dont realy get if you somewhere explain me that I can or cant link those dlls staticaly like all the other QT and System dlls into one big exe file containing all...
              when building static app, it works very vell for all those QT and System libs... so i realy have only one big EXE file...
              tho these external libs are just not included... but as far as i copy them manualy to the folder where the built app is, then all works fine...

              • unfortunatelly providing those DLLs is against the licence of the provider of this external libs, so I real ymust find a way how to protect them and not expose them

              Therefore, can you recommend any way of doing that?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #7

                Just as I said, you cannot link DLLs statically (DLL stands for Dynamic Link Library and as the name suggests they are linked dynamically and never statically).

                Why it does seem to work for you with Qt might have different reasons. You might have the Qt DLL directory in your PATH environment variable so that they are found by Windows. On another computer that does not have them installed it would not work. Or somehow you do have a static version of Qt that you are linking against. You can use tools like Dependency Walker (I think there is a newer tool replacing it) to figure out which DLLs your exe is looking for.

                As you cannot statically link DLLs you might only try to obfuscate their existence. One way (which I don't know much about) would be to embed the DLLs as a resource into the exe (via a .qrc file). Then, the DLLs needs to be explicitly loaded during startup. It seems like Qt has just the thing for you: https://doc.qt.io/qt-6/qlibrary.html . I would expect that QLibrary could work with resource file paths to load the DLL (something like ":/external/myprivate.dll")

                S 1 Reply Last reply
                0
                • S SimonSchroeder

                  Just as I said, you cannot link DLLs statically (DLL stands for Dynamic Link Library and as the name suggests they are linked dynamically and never statically).

                  Why it does seem to work for you with Qt might have different reasons. You might have the Qt DLL directory in your PATH environment variable so that they are found by Windows. On another computer that does not have them installed it would not work. Or somehow you do have a static version of Qt that you are linking against. You can use tools like Dependency Walker (I think there is a newer tool replacing it) to figure out which DLLs your exe is looking for.

                  As you cannot statically link DLLs you might only try to obfuscate their existence. One way (which I don't know much about) would be to embed the DLLs as a resource into the exe (via a .qrc file). Then, the DLLs needs to be explicitly loaded during startup. It seems like Qt has just the thing for you: https://doc.qt.io/qt-6/qlibrary.html . I would expect that QLibrary could work with resource file paths to load the DLL (something like ":/external/myprivate.dll")

                  S Offline
                  S Offline
                  shokarta
                  wrote on last edited by
                  #8

                  @SimonSchroeder but i also have the LIB files... whic could mean they might be static... is there a way to confirm that?

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • S shokarta

                    @SimonSchroeder but i also have the LIB files... whic could mean they might be static... is there a way to confirm that?

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @shokarta said in Static version does not include external targetted libs:

                    but i also have the LIB files... whic could mean they might be static... is there a way to confirm that?

                    There is no static lib until you compiled Qt statically by yourself. And those static libs would be much larger than the dlls.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    S 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @shokarta said in Static version does not include external targetted libs:

                      but i also have the LIB files... whic could mean they might be static... is there a way to confirm that?

                      There is no static lib until you compiled Qt statically by yourself. And those static libs would be much larger than the dlls.

                      S Offline
                      S Offline
                      shokarta
                      wrote on last edited by
                      #10

                      There is no static lib until you compiled Qt statically by yourself.

                      but I have QT static version build from source myself.
                      or you mean compiling those libs myself?

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • S shokarta

                        There is no static lib until you compiled Qt statically by yourself.

                        but I have QT static version build from source myself.
                        or you mean compiling those libs myself?

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by Christian Ehrlicher
                        #11

                        @shokarta said in Static version does not include external targetted libs:

                        but I have QT static version build from source myself

                        If so then there will be no dlls around in the build folder. Same goes for some external libs.

                        Don't understand the static hype though...

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SimonSchroeder
                          wrote on last edited by
                          #12

                          @shokarta said in Static version does not include external targetted libs:

                          but I have QT static version build from source myself.

                          This explains why you don't need the Qt DLLs. (Very few people actually try to compile a static version of Qt because it makes it harder to comply with the LGPL.)

                          @shokarta said in Static version does not include external targetted libs:

                          but i also have the LIB files... whic could mean they might be static... is there a way to confirm that?

                          I am not really an expert in this. My best guess is to use dumpbin or lib (Microsoft tools shipped with their compiler). Hopefully the symbols state if they are for a DLL or static lib.

                          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