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. Unable to static build the application using QML
Forum Updated to NodeBB v4.3 + New Features

Unable to static build the application using QML

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 381 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.
  • B Offline
    B Offline
    bridge12
    wrote on last edited by
    #1

    I am working on a desktop Qt (6.2.0) application with UI built on QML (used through resource). I am looking forward to create static build for this application, but it fails because libGLX.a is not available. I tried static linking to this dynamic library which failed for obvious reason (error is provided below).
    I am using QtCreator from online installer and using below provided options to do cmake. Any suggestions on how to get through this? CMakeLists file and cmake options are provided for reference.

    cmake_minimum_required(VERSION 3.16) 
    
    # Set a custom variable for the home directory
    set(HOME_DIRECTORY $ENV{HOME})
    
    # Set the project name and version
    project(FMSApp VERSION 1.0.0 LANGUAGES CXX)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_AUTOUIC ON)
    
    # Find the Qt libraries
    find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Qml Charts)
    
    # Add the executable
    qt_add_executable(FMS
        src/main.cpp
        src/ZmqSubscriber.cpp
        src/ZmqSubscriber.h
        fmsapp.qrc
    )
    
    Set(-DQT_DEBUG_FIND_PACKAGE=ON)
    set(ZMQ_INCLUDE_DIR ${HOME_DIRECTORY}/FMSApp/include)
    set(ZMQ_LIB_DIR ${HOME_DIRECTORY}/FMSApp/libs/desktop/libzmq.a)
    
    # Link the Qt libraries and ZeroMQ to the target
    target_link_libraries(FMS
        PRIVATE
        Qt6::Core
        Qt6::Gui
        Qt6::Widgets
        Qt6::Qml
        Qt6::Charts
        ${ZMQ_LIB_DIR}
    )
    
    # Exclude specific libraries from static linking
    find_library(GLX_LIB NAMES GLX)
    find_library(GL_LIB NAMES GL)
    
    target_link_libraries(FMS PRIVATE ${GLX_LIB} ${GL_LIB})
    
    set_property(TARGET FMS APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android)
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bdynamic -lGL -lGLX -Wl,-Bstatic")
    
     cmake -S /home/user/FMSApp -B /home/user/FMSApp/build/Qt_Static-Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/user/qt-everywhere-src-6.7.2/build-static -DQT_QMAKE_EXECUTABLE=/home/user/qt-everywhere-src-6.7.2/build-static/bin/qmake -G "Unix Makefiles"
    
    user@BTLinux:~/FMSApp$ make
    [ 11%] Automatic MOC and UIC for target FMS
    [ 11%] Built target FMS_autogen
    [ 22%] Linking CXX executable FMS
    /usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libGLX.so'
    collect2: error: ld returned 1 exit status
    make[2]: *** [CMakeFiles/FMS.dir/build.make:444: FMS] Error 1
    make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/FMS.dir/all] Error 2
    make: *** [Makefile:91: all] Error 2
    
    jsulmJ 1 Reply Last reply
    1
    • B bridge12

      I am working on a desktop Qt (6.2.0) application with UI built on QML (used through resource). I am looking forward to create static build for this application, but it fails because libGLX.a is not available. I tried static linking to this dynamic library which failed for obvious reason (error is provided below).
      I am using QtCreator from online installer and using below provided options to do cmake. Any suggestions on how to get through this? CMakeLists file and cmake options are provided for reference.

      cmake_minimum_required(VERSION 3.16) 
      
      # Set a custom variable for the home directory
      set(HOME_DIRECTORY $ENV{HOME})
      
      # Set the project name and version
      project(FMSApp VERSION 1.0.0 LANGUAGES CXX)
      set(CMAKE_INCLUDE_CURRENT_DIR ON)
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      set(CMAKE_AUTOUIC ON)
      
      # Find the Qt libraries
      find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Qml Charts)
      
      # Add the executable
      qt_add_executable(FMS
          src/main.cpp
          src/ZmqSubscriber.cpp
          src/ZmqSubscriber.h
          fmsapp.qrc
      )
      
      Set(-DQT_DEBUG_FIND_PACKAGE=ON)
      set(ZMQ_INCLUDE_DIR ${HOME_DIRECTORY}/FMSApp/include)
      set(ZMQ_LIB_DIR ${HOME_DIRECTORY}/FMSApp/libs/desktop/libzmq.a)
      
      # Link the Qt libraries and ZeroMQ to the target
      target_link_libraries(FMS
          PRIVATE
          Qt6::Core
          Qt6::Gui
          Qt6::Widgets
          Qt6::Qml
          Qt6::Charts
          ${ZMQ_LIB_DIR}
      )
      
      # Exclude specific libraries from static linking
      find_library(GLX_LIB NAMES GLX)
      find_library(GL_LIB NAMES GL)
      
      target_link_libraries(FMS PRIVATE ${GLX_LIB} ${GL_LIB})
      
      set_property(TARGET FMS APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android)
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bdynamic -lGL -lGLX -Wl,-Bstatic")
      
       cmake -S /home/user/FMSApp -B /home/user/FMSApp/build/Qt_Static-Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/user/qt-everywhere-src-6.7.2/build-static -DQT_QMAKE_EXECUTABLE=/home/user/qt-everywhere-src-6.7.2/build-static/bin/qmake -G "Unix Makefiles"
      
      user@BTLinux:~/FMSApp$ make
      [ 11%] Automatic MOC and UIC for target FMS
      [ 11%] Built target FMS_autogen
      [ 22%] Linking CXX executable FMS
      /usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libGLX.so'
      collect2: error: ld returned 1 exit status
      make[2]: *** [CMakeFiles/FMS.dir/build.make:444: FMS] Error 1
      make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/FMS.dir/all] Error 2
      make: *** [Makefile:91: all] Error 2
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @bridge12 said in Unable to static build the application using QML:

      Any suggestions on how to get through this?

      You have to have all required libraries as static libraries.
      This also applies to Qt libraries.

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

      B 1 Reply Last reply
      0
      • jsulmJ jsulm

        @bridge12 said in Unable to static build the application using QML:

        Any suggestions on how to get through this?

        You have to have all required libraries as static libraries.
        This also applies to Qt libraries.

        B Offline
        B Offline
        bridge12
        wrote on last edited by
        #3

        @jsulm I have all Qt libraries compiled statically. I am unable to get libGLX.a. I am trying to compile mesa but it doesn't appear to be a piece of cake.

        1 Reply Last reply
        1
        • C Offline
          C Offline
          carlowilhelm
          wrote on last edited by
          #4

          @bridge12 , any progress with this? (I am having the same problem myself.)

          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