我想构建一个动态链接QT-Core库的c ++程序。
为此,我使用WSL作为构建环境,并使用CLion作为我的IDE。 当我在WSL(ubuntu_18.04)中编译该程序时,链接器找不到QtLibrary,但是当我在docker容器(ubuntu_18.04)中对其进行编译时,链接器会找到该库。
对此我感到很困惑,因为在我看来我已经正确设置了库搜索路径。 任何人都知道这可能是什么原因造成的吗?
我的项目结构如下:
apps
- CMakeLists.txt
- main.cpp
extern
- qt-linux
src
- CMakeLists.txt
- functions.cpp
- functions.hpp
toolschains
- linux-toolchain.cmake
CMakeLists.txt
build.sh
CMakeLists.txt文件如下:
CMakeLists.txt: cmake_minimum_required(版本3.10) 项目(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)
然后使用以下build.sh脚本进行构建:
#!/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输出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输出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)
答案 0 :(得分:1)
我现在想出了这个 问题在于libQt5Core.so.5是使用.note.ABI标签设置的,该标签设置为与WSL标识为(4.4)不兼容,但Docker容器兼容(4.9)的版本。
类似于这里发生的情况: https://github.com/Microsoft/WSL/issues/3023