Ask Your Question
4

Trouble with Catkin: Compiling node and generating messages in same package.

asked 2013-06-06 06:12:36 -0500

Raptor gravatar image

updated 2013-06-12 22:48:38 -0500

130s gravatar image

Hi Guys,

I am currently catkinizing the ublox driver found here: https://github.com/tu-darmstadt-ros-pkg/ublox

The node "ublox_msgs" builds a library and generates a number of messages at the same time. The library that is built in the package depends on the generated message header files that is created during compile time.

The problem is that it tries to compile the library without waiting for all the message headers to all be generated. The result is a error that it can not find one of the generated header files. For example:

../../ublox_msgs/include/ublox_msgs/ublox_msgs.h:41:35: fatal error: ublox_msgs/NavTIMEGPS.h: No such file or directory

I can see the messages being generated, and if I run "cakin_make" multiple times, it will generate all the headers and no longer error out. But I would like it to generate the message headers and then compile the library, so a error does not happen. I know the library and the messages should probably be in separate packages, but I just wanted to get it working in its current state.

I tried following what was referenced in this post, but it did not seem to work either: http://answers.ros.org/question/53265/catkin-messages-and-node-in-same-package/

Here is my package.xml file:

<?xml version="1.0"?>
<package>
  <name>ublox_msgs</name>
  <version>0.0.0</version>
  <description>
  </description>

  <maintainer email="jane.doe@example.com">Jane Doe</maintainer>
  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>message_generation</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>ublox_serialization</build_depend>

  <run_depend>message_runtime</run_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>ublox_serialization</run_depend>

  <export>
  </export>
</package>

Here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.3)
project(ublox_msgs)

find_package(catkin REQUIRED COMPONENTS genmsg ublox_serialization roscpp)

## Generate messages in the 'msg' folder
add_message_files(
    DIRECTORY msg
    FILES
    AidALM.msg
    AidEPH.msg
    AidHUI.msg
    CfgANT.msg
    CfgCFG.msg
    CfgMSG.msg
    CfgNAV5.msg
    CfgPRT.msg
    CfgRATE.msg
    CfgSBAS.msg
    NavCLOCK.msg
    NavDGPS.msg
    NavDGPS_SV.msg
    NavDOP.msg
    NavPOSECEF.msg
    NavPOSLLH.msg
    NavSBAS.msg
    NavSBAS_SV.msg
    NavSOL.msg
    NavSTATUS.msg
    NavSVINFO.msg
    NavSVINFO_SV.msg
    NavTIMEGPS.msg
    NavTIMEUTC.msg
    NavVELECEF.msg
    NavVELNED.msg
    RxmALM.msg
    RxmEPH.msg
    RxmRAW.msg
    RxmRAW_SV.msg
    RxmSFRB.msg
    RxmSVSI.msg
    RxmSVSI_SV.msg
)

## Generate added messages and services with any dependencies listed here
 generate_messages()

catkin_package(
   INCLUDE_DIRS include
   LIBRARIES ${PROJECT_NAME}
#  CATKIN_DEPENDS message_runtime
#  DEPENDS ublox_msgs
)

include_directories(include
  ${catkin_INCLUDE_DIRS}
)

## Declare a cpp library
add_library(ublox_msgs
   src/ublox_msgs.cpp
)

## Add cmake target dependencies of the executable/library
## as an example, message headers may need to be generated before nodes
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_gencpp)

## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})

I tried to follow the tutorials as much as possible: https://github.com/ros/catkin_tutorials/blob/master/create_package_pubsub/catkin_ws/src/beginner_tutorials/CMakeLists.txt

Does anyone see a issue in these files? Or maybe there is still a bug in Catkin?

Thank you for your help.


Update

So it looks like it works with catkin_make -j1 but NOT with just catkin_make. So it seems to be possibly a bug with running multiple jobs at once ... (more)

edit retag flag offensive close merge delete

Comments

Can you post the entire output of catkin_make -j1 on a previously unbuilt workspace? Your package looks ok to me, I don't see why you would be getting the out of order build bug (I can pretty confidently confirm that this is that bug since you can resolve it by running multiple times).

William gravatar imageWilliam ( 2013-06-06 10:42:24 -0500 )edit

Look at update above.

Raptor gravatar imageRaptor ( 2013-06-07 03:51:11 -0500 )edit

Why is CATKIN_DEPENDS message_runtime commented out? What happens when you use it?

joq gravatar imagejoq ( 2013-06-07 07:01:16 -0500 )edit

I do not see a difference if I use it or not, at least during compile time.

Raptor gravatar imageRaptor ( 2013-06-07 07:12:42 -0500 )edit

I think it is needed for other catkin packages that use your messages.

joq gravatar imagejoq ( 2013-06-07 07:15:00 -0500 )edit

Alright I will keep that in then.

Raptor gravatar imageRaptor ( 2013-06-07 07:20:28 -0500 )edit

4 Answers

Sort by ยป oldest newest most voted
1

answered 2013-06-06 11:56:07 -0500

joq gravatar image

updated 2013-06-07 03:58:06 -0500

UPDATED to remove incorrect suggestion, see comments below.

The currently-recommended variable name for expanding self-defined messages and services is:

add_dependencies(uuid_msgs ${${PROJECT_NAME}_EXPORTED_TARGETS})

I wrote that using the uuid_msgs target, because others reading this question may be confused by the fact that your library target has the same name as your package.

edit flag offensive delete link more

Comments

I think that ${${PROJECT_NAME}_gencpp} will not work, that would be dereferencing a target (${PROJECT_NAME}_gencpp is a target). The second recommendation is definitely correct.

William gravatar imageWilliam ( 2013-06-06 11:58:34 -0500 )edit

The line from above: "add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_gencpp})" does not seem to work. Here is the error that is produced: "CMake Error at ublox_msgs/CMakeLists.txt:108 (add_dependencies): add_dependencies called with incorrect number of arguments"

Raptor gravatar imageRaptor ( 2013-06-07 03:15:00 -0500 )edit

Sorry for the mistake. I thought it was a CMake variable, but as @William said, it's a target. I'll update the answer. Did the other add_dependencies() work for you?

joq gravatar imagejoq ( 2013-06-07 03:55:47 -0500 )edit

No problem, I thank you guys for the help. I put the command "add_dependencies(ublox_msgs ${PROJECT_NAME}_EXPORTED_TARGETS)" in place of "add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_gencpp)" and got the same error, that it could not find one of the generated header files from the messages.

Raptor gravatar imageRaptor ( 2013-06-07 04:14:31 -0500 )edit

Don't forget the double evaluation: ${${PROJECT_NAME}_EXPORTED_TARGETS}

joq gravatar imagejoq ( 2013-06-07 04:32:13 -0500 )edit

If I add the double evaluation, "add_dependencies(ublox_msgs ${${PROJECT_NAME}_EXPORTED_TARGETS})" I get the cmake error: "CMake Error at ublox_msgs/CMakeLists.txt:68 (add_dependencies): add_dependencies called with incorrect number of arguments" like the one above.

Raptor gravatar imageRaptor ( 2013-06-07 04:39:01 -0500 )edit

What does message("exported targets: ${${PROJECT_NAME}_EXPORTED_TARGETS}") print? Sounds like it must be empty.

joq gravatar imagejoq ( 2013-06-07 04:44:31 -0500 )edit

It is empty. I guess I am unclear on how to use it. This is the only resource I found that has any documentation on it: http://farnsworth.csres.utexas.edu/docs/catkin/html/howto/building_msgs.html and it does not tell you how to really use it.

Raptor gravatar imageRaptor ( 2013-06-07 06:13:43 -0500 )edit
3

answered 2013-06-07 08:04:56 -0500

jbohren gravatar image

updated 2013-06-07 08:06:13 -0500

Since targets are now built with plain CMake macros (add_executable, add_library, etc), there's no longer a list of targets built by a given package, and thus, a dependency cannot be made on messages first. What you need to do, for a given project is explicitly add a dependency on the CMake target representing the message generation step for that language. If the project name is "foo_pkg" and is written in c++ then this target names is "foo_pkg_gencpp" in CMakeLists.txt this looks like:

project_name(foo_pkg)
# ...
# For a library
add_library(foo src/foo_lib.cpp)
add_dependencies(foo ${PROJECT_NAME}_gencpp)
# For an executable
add_executable(foo_node srd/foo_node.cpp)
add_dependencies(foo_node ${PROJECT_NAME}_gencpp)

This is actually documented here (maybe it could be put in a more obvious place): http://ros.org/wiki/catkin/CMakeLists.txt#Important_Prerequisites.2BAC8-Constraints

See an example here:

https://github.com/jhu-lcsr-forks/ros_control/blob/bb356c02223dadcdafce635a43d2a8e4d12df23d/control_toolbox/CMakeLists.txt

edit flag offensive delete link more

Comments

I believe this is what I have. Could the problem be that the project_name is the same as the library name?

Raptor gravatar imageRaptor ( 2013-06-07 08:28:49 -0500 )edit

No, that wouldn't be a problem. They're also the same in control_toolbox.

jbohren gravatar imagejbohren ( 2013-06-07 08:31:41 -0500 )edit

His code does this and this will be deprecated in favor of using the ${PROJECT_NAME}_EXPORTED_TARGETS cmake variable, see:https://groups.google.com/forum/#!msg/ros-sig-buildsystem/dvVO5QCHBLM/_Ry8ioEGmpgJ

William gravatar imageWilliam ( 2013-06-07 08:36:05 -0500 )edit

Here is the repository with the code that is producing this error: https://github.com/raptort3000/ublox_catkin

Raptor gravatar imageRaptor ( 2013-06-07 10:18:37 -0500 )edit
2

answered 2013-06-07 11:05:36 -0500

William gravatar image

The error is occurring in the ublox_gps package not the ublox_msgs package, which is setup correctly. I have addressed the problem and given some other feed back in a pull request:

https://github.com/raptort3000/ublox_catkin/pull/1

edit flag offensive delete link more

Comments

I pulled down the pull request and it still reports a error. I commented on the pull request the error.

Raptor gravatar imageRaptor ( 2013-06-10 04:06:40 -0500 )edit

I commented on the pull request I think that you'll have to use the target name explicitly, ublox_msgs_generate_messages_cpp, until you start using genmsg >= 0.4.18, which should be in public repositories in a week or so.

William gravatar imageWilliam ( 2013-06-10 06:28:38 -0500 )edit
0

answered 2015-05-28 15:32:12 -0500

TinGoose gravatar image

Good day.

Seems like we have the similar issue. We have core project 'sybo_base' that defines some messages and nodes ('broadcaster', 'feeder') that use this message, and several other projects in the workspace that depend on sybo_base.

We've specified all the sort of dependencies for target (tried all of mentioned variants):

add_executable(broadcaster broadcaster.cpp utils.cpp)
add_dependencies(broadcaster ${${PROJECT_NAME}_EXPORTED_TARGETS})

And it anyways tries to build target 'broadcaster' before 'sybo_base_generate_messages_cpp' I've tried to check actual contents of mentioned variables

message(STATUS "broadcaster needs the following targets ${${PROJECT_NAME}_EXPORTED_TARGETS}")
target_link_libraries(broadcaster ${catkin_LIBRARIES} sybo_base)

CMake has produced the following output:

-- sybo_base: 5 messages, 2 services
-- sybo_base includes :/opt/ros/indigo/include;/usr/include
-- broadcaster needs the following targets sybo_base_generate_messages_cpp;sybo_base_generate_messages_lisp;sybo_base_generate_messages_py

It looks ok, the necessary dependencies are listed. When i try to build sybo_base 'separately', like

cd catkin_ws/build
make -j4 sybo_base

it builds nice. But when I try to build full workspace (of ~12 catkin projects in it) - build fails because of building 'broadcaster' before generating messages for it

edit flag offensive delete link more

Comments

1

As mentioned on the issue you filled please post the complete CMake code as well as the exact error message. If I have to guess based on you incomplete snippet you lack the dependencies for the sybo_base target.

Dirk Thomas gravatar imageDirk Thomas ( 2015-05-28 16:01:47 -0500 )edit
1

Also please don't your question as an answer. Better ask a new question and reference it in a comment.

Dirk Thomas gravatar imageDirk Thomas ( 2015-05-28 16:02:55 -0500 )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

2 followers

Stats

Asked: 2013-06-06 06:12:36 -0500

Seen: 9,419 times

Last updated: Jun 07 '13