0

我已经构建了 qt6 (6.2.0) 静态库。尝试在我的 cmake 项目(OS Ubuntu 20.04)中使用它并得到一个错误:

/usr/bin/ld: /home/balisong/project/../3rdparty/Qt/qt6/gcc_64/lib/libQt6Core.a(qtimezoneprivate_icu.cpp.o): undefined reference to symbol 'uenum_next_66'
/usr/bin/ld: /lib/x86_64-linux-gnu/libicuuc.so.66: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/project.dir/build.make:237: project] Error 1
make[1]: *** [CMakeFiles/Makefile2:338: CMakeFiles/project.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

我的 CMakeLists.txt:

project(project)
cmake_minimum_required (VERSION 3.8)
set(CMAKE_CXX_STANDARD 20)


set(QT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/Qt/qt6/gcc_64)
set(CMAKE_PREFIX_PATH ${QT_PATH})
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -no-pie")

#for qt6
find_package(Qt6 COMPONENTS Widgets Core Gui REQUIRED)

link_directories(${QT_PATH}/bin)
link_directories(${QT_PATH}/lib)
link_directories(${QT_PATH}/include/QtCore)
link_directories(${QT_PATH}/include/QtWidgets)
link_directories(${QT_PATH}/include/QtGui)
link_directories(${QT_PATH}/plugins/platforms)

if(CMAKE_VERSION VERSION_LESS "3.7.0")
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

SET(project_SRC
    "src/geometry.cpp" 
)

SET(qt_graphical_SRC
    "src/qt_graphical/qt_graphical.cpp" 
)

add_executable (project ${qt_graphical_SRC} ${project_SRC} ) 

set(LD_LIBRARY_PATH ${QT_PATH}/lib)

target_link_libraries(project
    PUBLIC
    Qt6Core
    Qt6Gui
    Qt6Widgets
    m
    png16
    jpeg
    z
    xcb-xfixes
    webpmux
    double-conversion
    icui18n
    zstd
    gthread-2.0
    harfbuzz
    dbus-1
    fontconfig
    udev
    mtdev
    input
    gbm
    gtk-3
    tiff
)

endif()    

target_compile_options(project PRIVATE -fPIC)

target_include_directories(project
  PUBLIC ${QT_PATH}/include
  PUBLIC ${QT_PATH}/include/QtCore
  PUBLIC ${QT_PATH}/include/QtWidgets
  PUBLIC ${QT_PATH}/include/QtGui
)

看起来我缺少依赖项中的一些库,但 libicu 已经是最新版本。

sudo apt-get install libicu66 libicu-dev

有什么建议可以解决这个问题吗?

4

1 回答 1

0

我通过在target_link_libraries添加icuuc来解决这个错误。实际上,我还在 target_link_libraries 中添加了glib -2.0pcre2-16pthreadQt6DBus以解决其他错误。

target_link_libraries(project
    PUBLIC
    Qt6Widgets
    Qt6Gui
    Qt6DBus 
    Qt6Core
    m
    png16
    jpeg
    z
    xcb-xfixes
    webpmux
    double-conversion
    icui18n
    zstd
    gthread-2.0
    harfbuzz
    dbus-1
    fontconfig
    udev
    mtdev
    input
    gbm
    gtk-3
    tiff
    icuuc
    glib-2.0 
    pcre2-16 
    pthread
)
于 2021-08-03T15:14:21.680 回答