使用clion和Qt5写程序时的链接问题

2 篇文章 0 订阅
1 篇文章 0 订阅

用mingw静态编译了qt5.5,然后用clion在qt库上写程序,遇到一堆链接问题,例如

"C:\Program Files (x86)\JetBrains\CLion 1.1.1\bin\cmake\bin\cmake.exe" --build C:\Users\wind\.clion11\system\cmake\generated\7bfc5903\7bfc5903\Release --target all -- -j 4
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/wind/.clion11/system/cmake/generated/7bfc5903/7bfc5903/Release
[ 25%] Automatic moc for target untitled
[ 25%] Built target untitled_automoc
[ 50%] Linking CXX executable untitled.exe
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2286): undefined reference to `hb_buffer_create'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x229d): undefined reference to `hb_buffer_set_unicode_funcs'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x22b0): undefined reference to `hb_buffer_pre_allocate'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x22b8): undefined reference to `hb_buffer_allocation_successful'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x23ac): undefined reference to `hb_buffer_clear_contents'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x23dc): undefined reference to `hb_buffer_add_utf16'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x23ef): undefined reference to `hb_buffer_set_segment_properties'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x23f7): undefined reference to `hb_buffer_guess_segment_properties'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2412): undefined reference to `hb_buffer_set_flags'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2489): undefined reference to `hb_shape_full'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x24ac): undefined reference to `hb_buffer_get_length'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x24c0): undefined reference to `hb_buffer_destroy'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2575): undefined reference to `hb_buffer_get_glyph_infos'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2589): undefined reference to `hb_buffer_get_glyph_positions'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x27c8): undefined reference to `hb_buffer_reverse'
G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x280e): undefined reference to `hb_buffer_destroy'
G:/dev/C++/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/C++/qt/lib/libQt5Gui.a(qtextengine.o): bad reloc address 0x9 in section `.text$_ZN5QListIN11QTextEngine14ItemDecorationEED1Ev[__ZN5QListIN11QTextEngine14ItemDecorationEED1Ev]'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\untitled.dir\build.make:136: recipe for target 'untitled.exe' failed
mingw32-make.exe[2]: *** [untitled.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/untitled.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/untitled.dir/all' failed
makefile:82: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2
以及

"C:\Program Files (x86)\JetBrains\CLion 1.1.1\bin\cmake\bin\cmake.exe" --build C:\Users\wind\.clion11\system\cmake\generated\7bfc5903\7bfc5903\Release --target all -- -j 4
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/wind/.clion11/system/cmake/generated/7bfc5903/7bfc5903/Release
[ 25%] Automatic moc for target untitled
[ 25%] Built target untitled_automoc
[ 50%] Linking CXX executable untitled.exe
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x261): undefined reference to `pcre16_exec'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x2c6): undefined reference to `pcre16_jit_stack_alloc'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x328): undefined reference to `pcre16_exec'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x57e): undefined reference to `pcre16_free'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x589): undefined reference to `pcre16_free_study'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x645): undefined reference to `pcre16_fullinfo'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x668): undefined reference to `pcre16_fullinfo'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x6be): undefined reference to `pcre16_fullinfo'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x7e0): undefined reference to `pcre16_config'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x9b3): undefined reference to `pcre16_compile2'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0xad9): undefined reference to `pcre16_study'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0xb00): undefined reference to `pcre16_assign_jit_stack'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0xc21): undefined reference to `pcre16_get_stringnumber'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x3f3e): undefined reference to `pcre16_fullinfo'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x3f62): undefined reference to `pcre16_fullinfo'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x3f86): undefined reference to `pcre16_fullinfo'
G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text$_ZN14QThreadStorageIP20QPcreJitStackPointerE10deleteDataEPv[__ZN14QThreadStorageIP20QPcreJitStackPointerE10deleteDataEPv]+0xffffb906): undefined reference to `pcre16_jit_stack_free'
G:/dev/C++/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/C++/qt/lib/libQt5Core.a(qregularexpression.o): bad reloc address 0x16 in section `.text$_ZN14QThreadStorageIP20QPcreJitStackPointerE10deleteDataEPv[__ZN14QThreadStorageIP20QPcreJitStackPointerE10deleteDataEPv]'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [untitled.exe] Error 1
CMakeFiles\untitled.dir\build.make:136: recipe for target 'untitled.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/untitled.dir/all' failed
makefile:82: recipe for target 'all' failed
mingw32-make.exe[1]: *** [CMakeFiles/untitled.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2

全是链接问题,需要对链接的库仔细查找添加,并且库的顺序非常重要,最终的cmake文件为

cmake_minimum_required(VERSION 3.3)
set(PROJECT_NAME abc)
project(${PROJECT_NAME})

set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -mwindows")

aux_source_directory(${PROJECT_SOURCE_DIR} SOURCE_FILES)
set(CPP_BASE G:/dev/C++)
include_directories(${CPP_BASE}/opencv/include/)
link_directories(${CPP_BASE}/qt/lib/)
link_directories(${CPP_BASE}/opencv/lib/)
link_directories(${CPP_BASE}/mingw32/i686-w64-mingw32/lib/)
link_directories(${CPP_BASE}/qt/plugins/platforms/)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})

set(CMAKE_PREFIX_PATH ${CPP_BASE}/qt)
find_package(Qt5Core)
qt5_use_modules(${PROJECT_NAME} Core Widgets Gui)
target_link_libraries(${PROJECT_NAME}  opencv_imgcodecs300 opencv_highgui300 opencv_core300 Qt5Core qtharfbuzzng qtpcre ws2_32 opengl32 qwindows Qt5PlatformSupport imm32 qtfreetype Qt5Gui winmm)

我这里还用了opencv,不需要可以删掉,main函数前面还要加上

Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

否则会出现错误

QT5 Failed to load platform plugin "windows" 



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值