使用 CMake 在 Windows 上针对 Qt 的静态链接



我正在做一个在Linux上开发的Qt项目,但也有一个静态链接的Windows版本。我可以使用相同的CMakeLists.txt文件在Linux和Windows上构建它。它剥离为:

project(muckturnier)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_REQUIRED TRUE)
find_package(Qt5 COMPONENTS Widgets Sql)
include_directories(${Qt5Widgets_INCLUDES} ${Qt5Sql_INCLUDES})
set(CMAKE_AUTOMOC ON)
set(muckturnier_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/SomeCode.cpp)
add_executable(muckturnier ${muckturnier_SRCS})
target_link_libraries(muckturnier ${Qt5Widgets_LIBRARIES} ${Qt5Sql_LIBRARIES})

但是我还没有设法通过CMake在Windows上进行静态链接构建。当我手动设置相应的包含目录时,一切都很好,但最终出现链接器错误:

[100%] Linking CXX executable muckturnier.exe
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x228d):
undefined reference to `hb_buffer_create'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x22a4):
undefined reference to `hb_buffer_set_unicode_funcs'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x22b7):
undefined reference to `hb_buffer_pre_allocate'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x22bf):
undefined reference to `hb_buffer_allocation_successful'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x23ef):
undefined reference to `hb_buffer_clear_contents'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x241f):
undefined reference to `hb_buffer_add_utf16'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2432):
undefined reference to `hb_buffer_set_segment_properties'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x243a):
undefined reference to `hb_buffer_guess_segment_properties'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2455):
undefined reference to `hb_buffer_set_flags'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2555):
undefined reference to `hb_shape_full'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2578):
undefined reference to `hb_buffer_get_length'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x258c):
undefined reference to `hb_buffer_destroy'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x264a):
undefined reference to `hb_buffer_get_glyph_infos'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2662):
undefined reference to `hb_buffer_get_glyph_positions'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x28f8):
undefined reference to `hb_buffer_reverse'
C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2941):
undefined reference to `hb_buffer_destroy'
C:/Qt/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w
64-mingw32/bin/ld.exe: C:/Qt/5.6_static/lib/libQt5Gui.a(qtextengine.o): bad relo
c address 0x7a in section `.text$_ZN7QVectorIN11QTextLayout11FormatRangeEEaSERKS
2_[__ZN7QVectorIN11QTextLayout11FormatRangeEEaSERKS2_]'
collect2.exe: error: ld returned 1 exit status
CMakeFilesmuckturnier.dirbuild.make:424: recipe for target 'muckturnier.exe' f
ailed
mingw32-make[2]: *** [muckturnier.exe] Error 1
CMakeFilesMakefile2:141: recipe for target 'CMakeFiles/muckturnier.dir/all' fai
led
mingw32-make[1]: *** [CMakeFiles/muckturnier.dir/all] Error 2
makefile:82: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

这就是为什么我创建了一个 qmake .pro 文件来执行静态构建。这个可以简化为:

QMAKE_CXXFLAGS += -std=c++11
CONFIG += qt
CONFIG += static
QT += widgets
QT += sql
HEADERS += SomeCode.h
SOURCES += SomeCode.cpp
TARGET = muckturnier

使用 qmake(来自静态 Qt),我可以毫无问题地进行静态构建。所以我的静态Qt构建很好,这是一个CMake问题。

这是怎么回事?感谢大家的帮助!

我认为你是这个错误的受害者(仍未解决)。我不是 100% 确定出了什么问题,但您可以在评论中找到一些想法。

相关内容

  • 没有找到相关文章

最新更新