Cmake和Qt5链接错误

时间:2015-06-14 11:46:11

标签: c++ qt cmake qt5

我正在尝试使用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

这是我的CMakeLists.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有关。

1 个答案:

答案 0 :(得分:2)

我认为您忘记将moc和资源附加到您的可执行文件qt5_wrap_cpp(),以便moc使用qt5_add_resources()获取资源。

然后您必须将变量附加到add_executable结帐this link