Ask Your Question

ROS built-in primitive types not declared

asked 2017-02-24 20:04:59 -0500

Kening Ren gravatar image

updated 2017-02-25 03:52:47 -0500

gvdhoorn gravatar image

Hello, I am new in using ROS. I see a problem with ROS built-in primitive type, such as int16.

Here is the code, it is very simple.

#include <ros/ros.h>

int main(int argc, char** argv)                                                                   
  int16 i = 0;
  ros::init(argc, argv, "data_broadcaster");                                                      
  ros::NodeHandle n;

  ros::Rate loop_rate(100);

    i = i + 4;
    if (i == 360) i = 0;                                                                          
  return 0;                                                                                       

I run catkin_make to build the code and get the following error.

[ 50%] Building CXX object data_capturer/CMakeFiles/data_broadcaster.dir/src/data_broadcaster.cpp.o
/home/kening/catkin_ws_2/src/data_capturer/src/data_broadcaster.cpp: In function ‘int main(int, char**)’:
/home/kening/catkin_ws_2/src/data_capturer/src/data_broadcaster.cpp:5:3: error: ‘int16’ was not declared in this scope
   int16 i = 0;
/home/kening/catkin_ws_2/src/data_capturer/src/data_broadcaster.cpp:17:5: error: ‘i’ was not declared in this scope
     i = i + 4;
data_capturer/CMakeFiles/data_broadcaster.dir/build.make:62: recipe for target 'data_capturer/CMakeFiles/data_broadcaster.dir/src/data_broadcaster.cpp.o' failed
make[2]: *** [data_capturer/CMakeFiles/data_broadcaster.dir/src/data_broadcaster.cpp.o] Error 1
CMakeFiles/Makefile2:837: recipe for target 'data_capturer/CMakeFiles/data_broadcaster.dir/all' failed
make[1]: *** [data_capturer/CMakeFiles/data_broadcaster.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

My CMakeLists.txt is:

cmake_minimum_required(VERSION 2.8.3)
find_package(catkin REQUIRED COMPONENTS
add_executable(data_broadcaster src/data_broadcaster.cpp)

My package.xml is:

<?xml version="1.0"?>
  <description>The data_capturer package</description>
  <maintainer email="">Ku</maintainer>



I could not figure out why int16 is not declared. Did I forget to include any header file. Or is there something wrong with my CMakeLists.txt and package.xml?

Please help. Thank you. -Kening

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-02-25 04:00:07 -0500

gvdhoorn gravatar image

updated 2017-02-25 04:01:43 -0500

I see a problem with ROS built-in primitive type, such as int16.

The only place where int16 is a legal identifier in a ROS context (ignoring custom type definitions in the various languages that have client libraries) is in the ROS msg specification. You cannot use those directly in any client code, as they are mapped onto types native to the language in which the client library is written.

For C++, int16 is mapped onto int16_t. int16 is not a type in C++, so the compiler error is to be expected.

Did I forget to include any header file

Add #include <cstdint> to your .cpp file and try again.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2017-02-24 20:04:59 -0500

Seen: 220 times

Last updated: Feb 25 '17