Arduino CMake error with custom message headers [closed]

asked 2017-01-15 21:54:53 -0500

Steven_Daniluk gravatar image

updated 2017-01-16 12:09:31 -0500

EDIT: This issue appears to be cause by a problem with rosserial not being able to find custom messages that are defined in the same package as the firmware. There is an issue on the rosserial github repo about this. The error below was an artifact of this problem. Since this seems to be a specific issue with rosserial, and they are aware of it, I'm going to close this question.

I have a script running on an arduino that uses custom messages, and it has worked successfully while being compiled and uploaded with the Arduino IDE. However, now I am attempting to use the CMake build system, and when running catkin_make I get an error that some includes in the pre-generated message header cannot be found:

Building CXX object CMakeFiles/nano328_arduino.dir/my_script_name.cpp.obj
In file included from /path_to_my_script/my_script_name.cpp:33:0:
/path_to_my_workspace/devel/include/my_package/MyMessage.h:9:18: fatal error: string: No such file or directory
 #include <string>

My arduino script first includes Arduino.h, then ros.h, then my message. The top of the generated message header is as follows:

#include <string>
#include <vector>
#include <map>

#include <ros/types.h>
#include <ros/serialization.h>
#include <ros/builtin_message_traits.h>
#include <ros/message_operations.h>

#include <std_msgs/Header.h>

It appears that the arduino target isn't being linked against the C++ standard libraries and can't find string, vector, or map. This is only for the arduino script, all my other executables using these messages build successfully.

A few interesting things:

  • Initially this was building successfully, but after cleaning my workspace by deleting the devel and build folders I get this error
  • If I build this from within the CLion IDE there are no errors and the arduino script is built successfully

Any ideas what I could be missing here? It is very strange that the catkin build fails while the CLion build succeeds.

Based on every example I have found I believe both of my CMakeLists are correct, but I will post them anyways. Here is the relevant sections of my CMakeLists.txt in my package directory:

cmake_minimum_required(VERSION 2.8.3)
project(ghost)

## Find catkin macros and libraries
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  message_generation
  nodelet
  roscpp
  rosserial_arduino
  rosserial_client
  sensor_msgs
  std_msgs
  tf
)

## Declare custom messages
add_message_files(
  FILES
  MyMessage.msg
)

generate_messages(
  DEPENDENCIES
  std_msgs
)

# Declare the catkin package
catkin_package()

## Specify additional locations of header files
include_directories(
  ${catkin_INCLUDE_DIRS}
)

# Library generation for Arduino
rosserial_generate_ros_lib(
  PACKAGE rosserial_arduino
  SCRIPT make_libraries.py
)

# Arduino target setup
rosserial_configure_client(
  DIRECTORY arduino
  TOOLCHAIN_FILE ${ROSSERIAL_ARDUINO_TOOLCHAIN}
)
rosserial_add_client_target(arduino my_script_name ALL)
rosserial_add_client_target(arduino my_script_name-upload)

And here is the CMakeLists.txt in the arduino folder:

cmake_minimum_required(VERSION 2.8.3)

include_directories(${ROS_LIB_DIR})

generate_arduino_firmware(controller_interface
  SRCS controller_interface.cpp ${ROS_LIB_DIR}/time.cpp
  HDRS PinChangeInt.h
  BOARD nano328
  PORT /dev/ttyUSB0
)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Steven_Daniluk
close date 2017-01-16 12:07:14.758932

Comments

Did you find a solution to this? I am experiencing the same issue.

jdcarp gravatar image jdcarp  ( 2017-02-18 21:36:54 -0500 )edit

A workaround is to build the messages for rosserial_arduino and your arduino script, separately from the rest of your package. In the package's CMakeLists.txt remove "ALL" from rosserial_add_client_target(arduino my_script_name ALL), this will prevent CMake from automatically building the script.

Steven_Daniluk gravatar image Steven_Daniluk  ( 2017-02-19 08:34:19 -0500 )edit

To build everything, first run catkin_make, this will build the rest of your package. The from your workspace run rosserial_arduino make_libraries build/my_package to build the messages, then catkin_make my_package_arduino_my_script_name to build your script. Change the names accordingly.

Steven_Daniluk gravatar image Steven_Daniluk  ( 2017-02-19 08:36:16 -0500 )edit