0

I'm trying to build a Qt5 project with Cmake in order to add some new librairies. The cmake goes well but I have a linking issue when building :

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

Here is my 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})

I have also tried to add libraries with ${Qt5Widgets_INCLUDES} or ${Qt5Widgets_DEFINITIONS} but it did the same.

I've also tried to compile with QtCreator and it works so the problem is with cmake.

3
  • Maybe you also need to link Qt5::Gui. And enable automoc in CMake. Another thing that happens on some IDEs (Xcode for example) is: If you add the Q_OBJECT macro somewhere, you have to run CMake manually to generate the correspondig .moc file before compilation. Commented Jun 14, 2015 at 16:55
  • automoc is enabled in my CMakeLists.txt no ? I've tried to add some other modules (like Gui) but it did the same. For compiling, I've created an empty folder so it's a "fresh" compilation. Commented Jun 14, 2015 at 17:15
  • I just read about the same linker error here and it looks like it's an RCC issue (Qt resource file generation). You can enable autorcc just like automoc. Maybe that helps Commented Jun 14, 2015 at 19:06

1 Answer 1

2

I think you forget to append moc and resources to your executable use qt5_wrap_cpp() for mocs use qt5_add_resources() for resources.

Then you must append vars to add_executable check out this link.

Sign up to request clarification or add additional context in comments.

1 Comment

That solved my problem : I've missed to add .qrc files with qt5_add_resources(). But qt5_wrap_cpp() wasn't necessary thanks to automoc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.