KMK
KMK

Reputation: 1509

Static link libraries in Qt application with CMake

I'm trying to build a Qt5 application with static libraries using CMake, but I can't figure out how to link the files statically. I've been stuck on this for hours and tried to find any clues on google, but without luck.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.9 FATAL_ERROR)   

project (myDemo VERSION 0.1 LANGUAGES CXX)

### Didn't make any difference:
###set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
   
set (myDemo_VERSION_MAJOR 1)    
set (myDemo_VERSION_MINOR 0)

set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)    
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})    
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/installation)

set(CMAKE_AUTOMOC ON)

set(SOURCES ${PROJECT_SOURCE_DIR}/src)

#### This made the build process reach 100%, but still exiting with the same error message
###set(Qt5_USE_STATIC_LIBS ON)    
###set(Qt5_USE_STATIC_RUNTIME ON)

# Find the necessary qt libraries    
find_package(Qt5 COMPONENTS Gui Quick Qml Multimedia)

if ( NOT Qt5_FOUND )    
 message(FATAL_ERROR "Package QT not found!")    
endif( )

# add the executable    
add_executable(myDemo src/main.cpp     
    src/somefile.cpp     
    src/somefile.h )

target_include_directories(myDemo PRIVATE Qt5_DIR)    
target_compile_features(myDemo PUBLIC cxx_std_17)     

target_link_libraries (myDemo Qt5::Gui Qt5::Qml Qt5::Quick Qt5::Multimedia ${ADDITIONAL_LIBRARIES} -static)      

install (TARGETS myDemo DESTINATION bin)

The cmake command exits without errors, but the make command exits with the following error message:

/usr/bin/ld: attempted static link of dynamic object `/opt/qt5/lib/libQt5Quick.so.5.9.1'

collect2: error: ld returned 1 exit status

CMakeFiles/myDemo.dir/build.make:204: recipe for target '../bin/myDemo' failed

make[2]: *** [../bin/myDemo] Error 1

CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/myDemo.dir/all' failed

make[1]: *** [CMakeFiles/myDemo.dir/all] Error 2

Makefile:129: recipe for target 'all' failed

make: *** [all] Error 2

I'm running Ubuntu on a virtuel machine, and the application is implemented with QML/Qt (5.9). I'm using Virtual Studio Code (and not Qt Creator).

I have no prior experience with CMake.

Does anyone have any ideas how to link the static Qt libraries?

EDIT

The problem might be that I have the open source version of Qt. Could it be an explanation that the open source version doesn't support static builds?

Upvotes: 7

Views: 13999

Answers (2)

user8819
user8819

Reputation: 73

First, note this project https://github.com/siavashk/qt5-static-hello-world but it feels like it was only ever maybe successful on MacOS. Commenting out the set(QT_EXTRA_LIBS ... line in DoQtMess.cmake and the Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) line in main.cpp, it now builds and runs for me in Linux after running cmake without any static-specific arguments. However, I can see (using ldd) that it's dynamically linked to my system's Qt installation.

I am able to use a different installation of Qt by invoking cmake as:

$ export CMAKE_PREFIX_PATH="/path/to/other/qt/lib/cmake/Qt5"
$ cmake ..
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/qt5-static-hello-world-master/build
$ make -j 24
Scanning dependencies of target helloworld_autogen
[ 12%] Automatic MOC for target helloworld
[ 12%] Built target helloworld_autogen
[ 25%] Generating qrc_resources.cpp
[ 37%] Generating ui_mainwindow.h
Scanning dependencies of target helloworld
[ 50%] Building CXX object CMakeFiles/helloworld.dir/qrc_resources.cpp.o
[ 62%] Building CXX object CMakeFiles/helloworld.dir/helloworld_autogen/mocs_compilation.cpp.o
[ 75%] Building CXX object CMakeFiles/helloworld.dir/mainwindow.cpp.o
[ 87%] Building CXX object CMakeFiles/helloworld.dir/main.cpp.o
[100%] Linking CXX executable helloworld
[100%] Built target helloworld
$ ldd helloworld
        linux-vdso.so.1 (0x00007fff6a3f4000)
        libQt5Widgets.so.5 => /lib/x86_64-linux-gnu/libQt5Widgets.so.5 (0x00007f7e57460000)
        libQt5Gui.so.5 => /lib/x86_64-linux-gnu/libQt5Gui.so.5 (0x00007f7e56e75000)
        libQt5Core.so.5 => /lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f7e5692c000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7e5674a000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7e5672f000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7e5653b000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7e563ec000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7e563c9000)
        libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007f7e56341000)
        libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f7e56309000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7e562ed000)
        libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f7e561e6000)
        libicui18n.so.66 => /lib/x86_64-linux-gnu/libicui18n.so.66 (0x00007f7e55ee7000)
        libicuuc.so.66 => /lib/x86_64-linux-gnu/libicuuc.so.66 (0x00007f7e55d01000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7e55cfb000)
        libpcre2-16.so.0 => /lib/x86_64-linux-gnu/libpcre2-16.so.0 (0x00007f7e55c78000)
        libdouble-conversion.so.3 => /lib/x86_64-linux-gnu/libdouble-conversion.so.3 (0x00007f7e55c62000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f7e55b37000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f7e57b3e000)
        libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f7e55a7f000)
        libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f7e55a4b000)
        libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f7e5598c000)
        libgraphite2.so.3 => /lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f7e5595f000)
        libicudata.so.66 => /lib/x86_64-linux-gnu/libicudata.so.66 (0x00007f7e53e9c000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f7e53e29000)
        libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f7e53cec000)
        libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f7e53cc2000)
        libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f7e53cbc000)
        libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f7e53cb2000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f7e53c98000)

The output of ldd confirms that it will link to those .so's.

Using the same procedure but pointing CMAKE_PREFIX_PATH at a statically-compiled install tree, there certainly are a lot more files compiled:

cmake ..; make -j 24
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/qt5-static-hello-world-master/build
Scanning dependencies of target helloworld_autogen
[  2%] Automatic MOC for target helloworld
[  2%] Built target helloworld_autogen
[  4%] Generating ui_mainwindow.h
[  7%] Generating qrc_resources.cpp
Scanning dependencies of target helloworld
[  9%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QEglFSEmulatorIntegrationPlugin_Import.cpp.o
[ 11%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QEglFSKmsEglDeviceIntegrationPlugin_Import.cpp.o
[ 14%] Building CXX object CMakeFiles/helloworld.dir/helloworld_autogen/mocs_compilation.cpp.o
[ 16%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QWaylandEglPlatformIntegrationPlugin_Import.cpp.o
[ 19%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QTiffPlugin_Import.cpp.o
[ 21%] Building CXX object CMakeFiles/helloworld.dir/main.cpp.o
[ 23%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QICOPlugin_Import.cpp.o
[ 26%] Building CXX object CMakeFiles/helloworld.dir/mainwindow.cpp.o
[ 30%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QEglFSKmsGbmIntegrationPlugin_Import.cpp.o
[ 28%] Building CXX object CMakeFiles/helloworld.dir/qrc_resources.cpp.o
[ 33%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QEglFSX11IntegrationPlugin_Import.cpp.o
[ 38%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QICNSPlugin_Import.cpp.o
[ 38%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QGifPlugin_Import.cpp.o
[ 40%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QSvgIconPlugin_Import.cpp.o
[ 45%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QSvgPlugin_Import.cpp.o
[ 45%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QJpegPlugin_Import.cpp.o
[ 47%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QTgaPlugin_Import.cpp.o
[ 50%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_DrmEglServerBufferPlugin_Import.cpp.o
[ 52%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandBradientDecorationPlugin_Import.cpp.o
[ 54%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandEglClientBufferPlugin_Import.cpp.o
[ 57%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandFullScreenShellV1IntegrationPlugin_Import.cpp.o
[ 59%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandIviShellIntegrationPlugin_Import.cpp.o
[ 61%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandXCompositeEglClientBufferPlugin_Import.cpp.o
[ 64%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandWlShellIntegrationPlugin_Import.cpp.o
[ 66%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandXCompositeGlxClientBufferPlugin_Import.cpp.o
[ 69%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandXdgShellIntegrationPlugin_Import.cpp.o
[ 71%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandXdgShellV5IntegrationPlugin_Import.cpp.o
[ 73%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_QWaylandXdgShellV6IntegrationPlugin_Import.cpp.o
[ 76%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_ShmServerBufferPlugin_Import.cpp.o
[ 78%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5WaylandClient/Qt5WaylandClient_VulkanServerBufferPlugin_Import.cpp.o
[ 80%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QWaylandIntegrationPlugin_Import.cpp.o
[ 85%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QWaylandXCompositeGlxPlatformIntegrationPlugin_Import.cpp.o
[ 85%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QWaylandXCompositeEglPlatformIntegrationPlugin_Import.cpp.o
[ 88%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QWbmpPlugin_Import.cpp.o
[ 90%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QXcbEglIntegrationPlugin_Import.cpp.o
[ 92%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QWebpPlugin_Import.cpp.o
[ 95%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QXcbGlxIntegrationPlugin_Import.cpp.o
[ 97%] Building CXX object CMakeFiles/helloworld.dir/opt/Qt5.15.5-static/lib/cmake/Qt5Gui/Qt5Gui_QXcbIntegrationPlugin_Import.cpp.o
[100%] Linking CXX executable helloworld
[100%] Built target helloworld

And yay the output of ldd confirms that there are no references to dynamic Qt library (at least, not at launch time).

$ ldd helloworld
        linux-vdso.so.1 (0x00007fffa0d84000)
        libgbm.so.1 => /lib/x86_64-linux-gnu/libgbm.so.1 (0x00007f51f45cb000)
        libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f51f4546000)
        libtiff.so.5 => /lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f51f44c5000)
        libxcb-glx.so.0 => /lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007f51f44a8000)
        libdrm.so.2 => /lib/x86_64-linux-gnu/libdrm.so.2 (0x00007f51f4494000)
        libX11-xcb.so.1 => /lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f51f448d000)
        libxcb-icccm.so.4 => /lib/x86_64-linux-gnu/libxcb-icccm.so.4 (0x00007f51f4486000)
        libxcb-image.so.0 => /lib/x86_64-linux-gnu/libxcb-image.so.0 (0x00007f51f4281000)
        libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f51f427c000)
        libxcb-keysyms.so.1 => /lib/x86_64-linux-gnu/libxcb-keysyms.so.1 (0x00007f51f4277000)
        libxcb-randr.so.0 => /lib/x86_64-linux-gnu/libxcb-randr.so.0 (0x00007f51f4264000)
        libxcb-render-util.so.0 => /lib/x86_64-linux-gnu/libxcb-render-util.so.0 (0x00007f51f425b000)
        libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f51f424c000)
        libxcb-shape.so.0 => /lib/x86_64-linux-gnu/libxcb-shape.so.0 (0x00007f51f4247000)
        libxcb-sync.so.1 => /lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007f51f423d000)
        libxcb-xfixes.so.0 => /lib/x86_64-linux-gnu/libxcb-xfixes.so.0 (0x00007f51f4233000)
        libxcb-xinerama.so.0 => /lib/x86_64-linux-gnu/libxcb-xinerama.so.0 (0x00007f51f422e000)
        libxcb-xkb.so.1 => /lib/x86_64-linux-gnu/libxcb-xkb.so.1 (0x00007f51f420e000)
        libxcb-xinput.so.0 => /lib/x86_64-linux-gnu/libxcb-xinput.so.0 (0x00007f51f41ea000)
        libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f51f41c0000)
        libSM.so.6 => /lib/x86_64-linux-gnu/libSM.so.6 (0x00007f51f41b5000)
        libICE.so.6 => /lib/x86_64-linux-gnu/libICE.so.6 (0x00007f51f4197000)
        libxkbcommon-x11.so.0 => /lib/x86_64-linux-gnu/libxkbcommon-x11.so.0 (0x00007f51f418c000)
        libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007f51f415d000)
        libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007f51f4158000)
        libEGL.so.1 => /lib/x86_64-linux-gnu/libEGL.so.1 (0x00007f51f4143000)
        libXcomposite.so.1 => /lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f51f413e000)
        libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f51f4001000)
        libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f51f3fba000)
        libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f51f3ef9000)
        libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007f51f3eee000)
        libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007f51f3edd000)
        libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007f51f3e55000)
        libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f51f3e1d000)
        libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f51f3d18000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f51f3cfa000)
        libdouble-conversion.so.3 => /lib/x86_64-linux-gnu/libdouble-conversion.so.3 (0x00007f51f3ce4000)
        libicui18n.so.66 => /lib/x86_64-linux-gnu/libicui18n.so.66 (0x00007f51f39e5000)
        libicuuc.so.66 => /lib/x86_64-linux-gnu/libicuuc.so.66 (0x00007f51f37ff000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f51f37f9000)
        libpcre2-16.so.0 => /lib/x86_64-linux-gnu/libpcre2-16.so.0 (0x00007f51f3776000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f51f364b000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f51f3628000)
        libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f51f35e6000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f51f3404000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f51f32b5000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f51f329a000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f51f30a6000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f51f57af000)
        libwayland-server.so.0 => /lib/x86_64-linux-gnu/libwayland-server.so.0 (0x00007f51f3090000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f51f3062000)
        libwebp.so.6 => /lib/x86_64-linux-gnu/libwebp.so.6 (0x00007f51f2ff8000)
        libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f51f2f4f000)
        liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f51f2f26000)
        libjbig.so.0 => /lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f51f2d16000)
        libxcb-util.so.1 => /lib/x86_64-linux-gnu/libxcb-util.so.1 (0x00007f51f2b10000)
        libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f51f2b0a000)
        libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f51f2b02000)
        libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f51f2af9000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f51f2add000)
        libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f51f2a25000)
        libffi.so.7 => /lib/x86_64-linux-gnu/libffi.so.7 (0x00007f51f2a19000)
        libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f51f29e5000)
        libgraphite2.so.3 => /lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f51f29b8000)
        libicudata.so.66 => /lib/x86_64-linux-gnu/libicudata.so.66 (0x00007f51f0ef5000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f51f0e82000)

Here's the big takeaway: it seems to me that somewhere in the Qt-cmake integration/build-support workings, this is now a lot easier than it used to be. That is, when I tried doing this with Qt 5.12, I ended up inserting a lot of Q_IMPORT_PLUGIN lines, and it was a process of trial and error to figure out which ones were needed. So, I'm going to throw out there that the first step in statically linking Qt is to use version 5.15.

Best of all, it actually runs as expected!

Upvotes: 0

Sherif O.
Sherif O.

Reputation: 514

if you work in windows, i suggest to use MSYS2, then use pacman to install qt statically and install cmake and gcc (if you want to use pro files), this will reduce the work load hereafter. Then in Qt Creator adjust the kit compiler to use the static compiler from msys2 that you just installed because the compiler used for your application and the library must be the same. These commands are for the compiler, i dont remember the one to install the qt.

 pacman -S mingw-w64-x86_64-gcc

 gcc -v #to make sure gcc is installed

 g++ -v # check g++ compiler

 pacman -S make

 pacman --needed -S mingw-w64-x86_64-toolchain

If you work in Mac, the process would be the same but using brew, there will be one exception in your cmake file add this

set(CMAKE_EXE_LINKER_FLAGS "-lobjc -framework IOKit -framework CoreFoundation")

Upvotes: -1

Related Questions