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:
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
I am using QtCreator from online installer and using below provided options to do cmake.
CMakeLists file:
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")
...and cmake options are provided for reference:
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"
Any suggestions on how to get through this?