4

I use qt official example and get error:

/media/roroco/disk750/Downloads/qtbase/examples/widgets/desktop/systray/main.cpp:50: undefined reference to `qInitResources_systray()'

here is my CMakeLists.txt

SET(CMAKE_PREFIX_PATH /media/roroco/disk750/Downloads/qtbase)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets)
add_executable(systray main.cpp window.cpp)
target_link_libraries(systray Qt5::Widgets)

How to make this example work

DevSolar
  • 67,862
  • 21
  • 134
  • 209
iufachajov
  • 233
  • 2
  • 8
  • What you forgot is qrc file. You can add it to CMakeLists using qt5_add_resources – demonplus Feb 26 '16 at 17:11
  • Thanks I had the same issue with `CMake` and this helped. It turned out being a mismatched variable name because I use custom `CMake` helper functions so that Qt4 and Qt5 can be handled by the same CMakeLists.txt. – drescherjm Jul 12 '18 at 18:24

1 Answers1

4

according error message undefined reference to `qInitResources_systray()', I should use following CMakeLists.txt

cmake_minimum_required(VERSION 3.3)
project(systray)

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

SET(CMAKE_PREFIX_PATH /media/roroco/disk750/Downloads/qtbase)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Widgets)
add_executable(systray main.cpp window.cpp systray.qrc)
target_link_libraries(systray Qt5::Widgets)
iufachajov
  • 233
  • 2
  • 8
  • This did it for me; I was missing (my equivalent of) `systray.qrc` in the `add_executable` call – Jonathan E. Landrum Dec 29 '20 at 23:30
  • Not only should you add `systray.qrc` in the `add_executable` but also make sure to have CMake variable `set(CMAKE_AUTORCC ON)` set. This will handle `rcc` automatically for Qt targets. – Mitja Kukovec Aug 21 '23 at 09:59