Ask Your Question
2

Qt and non-Qt nodes in the same package?

asked 2012-02-27 18:59:44 -0600

pmwalk gravatar image

updated 2014-01-28 17:11:27 -0600

ngrennan gravatar image

I have used qt_create to make a Qt ROS package. However, when I try to add another basic ROS node (one that doesn't use Qt), I get the following error, stating that I have duplicate main functions:

  make[3]: Entering directory `/home/phillip/ROS_workspace/ros-swarm-tools/interpreter/build'
  Linking CXX executable ../bin/interface
  CMakeFiles/interface.dir/src/interpreter.o: In function `main':
  /home/phillip/ROS_workspace/ros-swarm-tools/interpreter/src/interpreter.cpp:158: multiple definition of `main'
  CMakeFiles/interface.dir/src/main.o:/home/phillip/ROS_workspace/ros-swarm-tools/interpreter/src/main.cpp:20: first defined here
  collect2: ld returned 1 exit status

It seems as though cmake is trying to link the new ROS node (interpreter) with the old one (interface) in the ../bin/ folder. I am not familiar enough with cmake to know how to modify CMakeLists.txt to prevent it from doing this. Am I right in thinking that this is the problem? If so, how would I go about fixing it, or is there an easy tutorial somewhere for combining multiple nodes in a ROS Qt project?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2012-02-27 19:42:53 -0600

Daniel Stonier gravatar image

The qt_create script by default sets up a package for development of a single binary (keeps it simple).

The easiest way to get around it is to simply create two different packages. Or if you want to share some code between the two, one library package and two binary packages that depend on the library package.

I don't know how complicated your source structure setup, but the cmake you probably want to look at is the line in CMakeLists.txt:

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

That one assigns all the .cpp files under the src directory to QT_SOURCES and uses them to build the qt program. It's collecting the sources for both your mains together. Instead of globbing for sources, just comment that and assign sources manually. e.g.

set(QT_SOURCES src/main.cpp src/qnode.cpp src/main_window.cpp)
set(OTHER_SOURCES src/other_main.cpp)
rosbuild_add_executable(qfoo ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
rosbuild_add_executable(foo ${OTHER_SOURCES}) # non qt node

If you don't mind really learning the cmake though - check the qt_tutorials package for a complicated example of combining a build of a library and several nodes in the one package.

edit flag offensive delete link more

Comments

Perfect! That's exactly what I needed. I am planning on learning cmake for sure, but I wanted to try and fix this as soon as possible.

pmwalk gravatar imagepmwalk ( 2012-02-28 08:15:40 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-02-27 18:59:44 -0600

Seen: 641 times

Last updated: Feb 27 '12