user24151698
user24151698

Reputation: 1

ROS2 and QT5 - Undefined refernce to 'main' by using SET(CMAKE_AUTOMOC ON)

I want to migrate my ROS1 QT GUI to ROS2 Humble. However, when I try to compile after completing all the necessary code changes, I get the following error message:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main' collect2: error: ld returned 1 exit status

This error message always comes when I set the FLAG(CMAKE_AUTO_MOC on) flag. However, if I don't do this, it won't find many objects. Does anyone here have a solution?

The Cmake-file:

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(cas_interfaces REQUIRED)

find_package(Threads REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
find_package(Qt5Network REQUIRED)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTOUIC ON)
SET(CMAKE_AUTORCC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

list(APPEND CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/qt5")
list(APPEND CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/cmake")


add_executable(Example_XYZ_visualization_node
  src/Example_XYZ_visualization_gui.cpp
  #include/Example_XYZ_visualization/Example_XYZ_visualization_gui.h
  include/Example_XYZ_visualization_gui.h
  src/qcustomplot.h
  src/qcustomplot.cpp
  ${QT_RESOURCES_CPP} ${QT_MOC_HPP}
  ../Example_XYZ_adv/src/Example_XYZSignal.cpp
  ../Example_XYZ_adv/src/Example_XYZSignalProcessor.cpp
)


ament_target_dependencies(Example_XYZ_visualization_node 
  rclcpp
  std_msgs
  sensor_msgs
  xyz_interfaces
  Qt5Core
  Qt5Widgets
  Qt5PrintSupport
)

target_link_libraries( Example_XYZ_visualization_node 
 Threads::Threads
 ${Qt5Core_LIBRARIES}
 ${Qt5Network_LIBRARIES}
 ${Qt5Widgets_LIBRARIES}
 ${Qt5PrintSupport_LIBRARIES}

) 

I couldn't find a solution for the that problem to comple the GUI

Upvotes: 0

Views: 171

Answers (0)

Related Questions