简体   繁体   中英

Dynamic linking of QT in WSL not working but working in docker container

I want to build a c++ program that dynamically links the QT-Core library.

For this I am using the WSL as my build environment and CLion as my IDE. When I compile this programm in the WSL (ubuntu_18.04) the linker does not find the QtLibrary but when I compile it in a docker container (ubuntu_18.04) the linker finds the library.

I am quite confused by this since it seems to me I have set the library search path correctly. Anyone got any idea what might be causing this ?

My project structure is the following:

apps
- CMakeLists.txt
- main.cpp
extern
- qt-linux
src
- CMakeLists.txt
- functions.cpp
- functions.hpp
toolschains
- linux-toolchain.cmake
CMakeLists.txt
build.sh

The CMakeLists.txt files look like this:

CMakeLists.txt: cmake_minimum_required(VERSION 3.10) project(cpp_hello_world)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/Install)
set(CMAKE_SKIP_BUILD_RPATH  FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")


# QT SETUP
if(UNIX)
    set(Qt5Core_DIR "extern/qt-linux/lib/cmake/Qt5Core")
    install(DIRECTORY ${PROJECT_SOURCE_DIR}/extern/qt-linux/lib/ DESTINATION 
    lib)
endif()
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Core)

add_subdirectory(src)
add_subdirectory(apps)

src/CMakeLists.txt:

set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_library(HelloLibrary SHARED functions.hpp functions.cpp)
target_link_libraries(HelloLibrary Qt5::Core)
target_include_directories(HelloLibrary PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})


install(TARGETS HelloLibrary DESTINATION lib)
install(FILES functions.hpp DESTINATION include)

apps/CMakeLists.txt:

add_executable(hello-world main.cpp)

target_link_libraries(hello-world HelloLibrary)
target_link_libraries(hello-world -static-libgcc -static-libstdc++)
install(TARGETS hello-world DESTINATION bin)

and I build using the following build.sh script:

#!/bin/bash

export SOURCE_DIR=$(pwd)
rm -R build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../toolchains/linux- 
    toolchain.cmake -G "CodeBlocks - Unix Makefiles" ${SOURCE_DIR}

make
make install

ldd output WSL:

    linux-vdso.so.1 (0x00007ffff62d6000)
    libHelloLibrary.so => /mnt/c/Users/ci/Documents/Development/cpp-cmake-prototype/Install/bin/../lib/libHelloLibrary.so (0x00007f7c96fb0000)
    libQt5Core.so.5 => not found
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7c96bb0000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7c97600000)
    libQt5Core.so.5 => not found
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7c96820000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7c965f0000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7c96250000)

ldd output Docker-Container:

    linux-vdso.so.1 (0x00007ffc6932a000)
    libHelloLibrary.so => /Install/bin/./../lib/libHelloLibrary.so (0x00007f36411db000)
    libQt5Core.so.5 => /Install/bin/./../lib/libQt5Core.so.5 (0x00007f3640c33000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3640842000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f3641715000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f36404b9000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f36402a1000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3640082000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f363fe65000)
    libicui18n.so.60 => /usr/lib/x86_64-linux-gnu/libicui18n.so.60 (0x00007f363f9c4000)
    libicuuc.so.60 => /usr/lib/x86_64-linux-gnu/libicuuc.so.60 (0x00007f363f60d000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f363f409000)
    libdouble-conversion.so.1 => /usr/lib/x86_64-linux-gnu/libdouble-conversion.so.1 (0x00007f363f1f8000)
    libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f363eee2000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f363eb44000)
    libicudata.so.60 => /usr/lib/x86_64-linux-gnu/libicudata.so.60 (0x00007f363cf9b000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f363cd29000)

I figured this one out now The problem was the libQt5Core.so.5 was build with .note.ABI-tag set to a version incompatible with what the WSL identifies as(4.4) but the docker container was compatible(4.9).

Similar to what happens here: https://github.com/Microsoft/WSL/issues/3023

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM