Linux上で開発されたQtプロジェクトに取り組んでいますが、静的にリンクされたWindowsビルドもあります。同じCMakeLists.txtファイルを使って、LinuxとWindows上にビルドできます。それは次のように細分化しています:CMakeを使ったWindows上でのQtとの静的リンク
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上で静的にリンクされたビルドをまだ管理していませんでした。私は手動で設定すると、それぞれがDIRSが含まれ、全てはうまく構築し、私は最終的にリンカエラーを取得:私は静的ビルドを行うにはqmakeの.PROファイルを作成した理由
[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_CXXFLAGS += -std=c++11
CONFIG += qt
CONFIG += static
QT += widgets
QT += sql
HEADERS += SomeCode.h
SOURCES += SomeCode.cpp
TARGET = muckturnier
qmake(静的なQtから)を使用すると、静的なビルドを問題なく実行できます。だから私の静的なQtビルドはうまくいきました。それはCMakeの問題です。
ここで何が間違っていますか?すべての助けてくれてありがとう!
特定のモジュールインクルードとライブラリの代わりにQt5_INCLUDESとQt5_LIBRARIESを使用してください。また、qmakeを使ってビルドすると、コマンドが実行され、Qtライブラリのリンクがリンクされます。それはあなたにいくつかの手がかりを与えるかもしれません。 –
'target_link_libraries(...)'の代わりに 'qt5_use_modules(muckturnier Widgets Sql)'を使った場合はどうなりますか? –
http://doc.qt.io/qt-5/cmake-manual.htmlによると、これを正しく読めば、このマクロは古いcmakeバージョンでのみ使用するべきですか?私は現在の安定したものを使いました。私は以下の恐怖ピペが正しいとバグだ...私はこれを確認するつもりです。 –