使用clion和Qt5写程序时的链接问题
2015-10-02 00:56
1296 查看
用mingw静态编译了qt5.5,然后用clion在qt库上写程序,遇到一堆链接问题,例如
全是链接问题,需要对链接的库仔细查找添加,并且库的顺序非常重要,最终的cmake文件为
我这里还用了opencv,不需要可以删掉,main函数前面还要加上
否则会出现错误
"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"
相关文章推荐
- VNC Viewer中启动qt5.5.0的qtcreator,报告QXcbConnection: Failed to initialize XRandr等,无法启动
- ZetCode PyQt4 tutorial Dialogs
- QT 布局管理器的嵌套使用
- ZetCode PyQt4 tutorial signals and slots
- QT中添加的资源文件qrc时的路径问题小结
- Ubuntu下Qt-4.7.1的静态编译
- 在QT程序中使用cout和cin
- 稀疏矩阵ADT_SeqTriple
- QT 内置标准对话框
- 编译Qt arm库并在开发板运行
- qt-solutions提供了8个开源项目
- Qt4 inputpanel 升级改造
- 可以供MFC调用的,QT实现的DLL(使用qt-solutions的qtwinmigrate实现)
- ZetCode PyQt4 tutorial layout management
- QT 让窗口(或控件)居中
- QTableWidget 用法总结(只能使用标准的数据模型,并且其单元格数据是QTableWidgetItem的对象)
- QT下int与QByteArray的转换
- 无法关闭的QT程序(覆盖closeEvent,新建QProcess并脱离关系)
- QT:不规则窗口的实现
- Qt源码分析之信号和槽机制