Cmake 和 Qt5 链接错误
Cmake and Qt5 linking error
我正在尝试使用 Cmake 构建一个 Qt5 项目,以便添加一些新的库。cmake 运行顺利,但我在构建时遇到了链接问题:
Linking CXX executable bin/qGo
CMakeFiles/qGo.dir/src/main.cpp.o: dans la fonction « main »:
main.cpp:(.text+0x102b): undefined reference to « qInitResources_application() »
collect2: error: ld returned 1 exit status
make[2]: *** [bin/qGo] Erreur 1
make[1]: *** [CMakeFiles/qGo.dir/all] Erreur 2
make: *** [all] Erreur 2
这是我的CMakeList.txt :
cmake_minimum_required(VERSION 2.8.11)
project (qGo)
SET(CMAKE_MODULE_PATH /usr/local/lib/cmake/)
# Répertoire d'installation de Qt5 (dépend de l'installation)
SET(CMAKE_PREFIX_PATH "~/Qt/5.4/gcc/")
find_package (OpenCV REQUIRED)
find_package (aruco REQUIRED)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Use moc files in the bin folder
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find the Qt5 components
find_package(Qt5Core)
find_package(Qt5Widgets)
find_package(Qt5Network)
find_package(Qt5Multimedia)
set(EXECUTABLE_OUTPUT_PATH bin)
SET(CMAKE_CXX_FLAGS "-std=c++11")
include_directories(src)
include_directories(src/audio)
include_directories(src/board)
include_directories(src/game_interfaces)
include_directories(src/game_tree)
include_directories(src/gtp)
include_directories(src/network)
include_directories(src/resources)
include_directories(src/sgf)
include_directories(src/translations)
file(
GLOB_RECURSE
source_files
src/*
)
file(
GLOB_RECURSE
ui_files
src/*.ui
)
file(
GLOB_RECURSE
header_files
src/*.h
src/*.hpp
)
QT5_WRAP_UI(header_ui ${ui_files})
# Tell CMake to create the helloworld executable
add_executable(qGo ${source_files} ${header_ui})
# Use the Widgets module from Qt 5.
target_link_libraries(qGo Qt5::Core Qt5::Widgets Qt5::Network Qt5::Multimedia ${OpenCV_LIBS} ${aruco_LIBS})
我也尝试添加带有 ${Qt5Widgets_INCLUDES} 或 ${Qt5Widgets_DEFINITIONS} 的库,但它做了同样的事情。
我也尝试使用QtCreator进行编译,它可以工作,所以问题出在cmake上。
我认为您忘记将moc和资源附加到可执行文件使用qt5_wrap_cpp()
用于mocs使用qt5_add_resources()
用于资源。
然后,您必须附加变量以add_executable
查看此链接。
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接