使用CMake在Windows上针对Qt进行静态链接 [英] Static linking against Qt on Windows using CMake

查看:93
本文介绍了使用CMake在Windows上针对Qt进行静态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究在Linux上开发的Qt项目,但是它具有静态链接的Windows版本.我可以使用相同的CMakeLists.txt文件在Linux和Windows上构建它.它简化为:

I'm working on a Qt project that is developed on Linux, but also has a statically linked Windows build. I can build it on Linux and Windows using the same CMakeLists.txt file. It strips down to:

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上进行静态链接构建.当我手动设置各自的包含目录时,所有构建都可以,但是最后却出现链接器错误:

But I didn't manage to do a statically linked build on Windows via CMake yet. When I manually set the respective include dirs, all builds fine, but I get a linker error in the end:

[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
CMakeFiles\muckturnier.dir\build.make:424: recipe for target 'muckturnier.exe' f
ailed
mingw32-make[2]: *** [muckturnier.exe] Error 1
CMakeFiles\Makefile2: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文件来进行静态构建的原因.这简写为:

This is why I created a qmake .pro file to do the static build. This one strips down to:

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的问题.

Using qmake (from the static Qt), I can do the static build without a problem. So my static Qt build is just fine, and it's a CMake problem.

这是怎么了?感谢所有帮助!

What's wrong here? Thanks for all help!

推荐答案

我认为您是此错误(仍未解决).我不是100%知道出了什么问题,但是您可以在评论中找到一些想法.

I think you're a victim of this bug (still unsolved). I'm not 100% sure of what's going wrong, but you can find some ideas in the comments.

这篇关于使用CMake在Windows上针对Qt进行静态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆