Ask Your Question

Compile error: ‘Init’ is not a member of ‘ros’

asked 2014-06-07 11:09:52 -0500

Kirill gravatar image

updated 2014-06-07 11:11:49 -0500

Ubuntu 12.04, ROS Hydro




Created ROS pack:

roscd chapter2_tutorials/src/

bin  build  CMakeLists.txt  include  lib  mainpage.dox  Makefile  manifest.xml  src

Test ROS Package has two source files:

cd src

example1_a.cpp  example1_b.cpp


#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>

int main(int argc, char **argv)
  ros::Init(argc, argv, "example1_a");
  ros::NodeHandle n;
  ros::Publisher chatter_pub = n.advertise<std_
msgs::String>("message", 1000);
  ros::Rate loop_rate(10);
  while (ros::ok())
    std_msgs:String msg;
    std::stringstream ss;
    ss << " I am the example_a node "; = ss.str();
  return 0;


#include "ros/ros.h"
#include "std_msgs/String.h"

void chatterCallback(const std_msgs::String::ConstPtr& msg)
  ROS_INFO("I heard: [%s]", msg->data.c_str());

int main (int argc, char **argv)
  ros::Init(argc, argv, "example1_b");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subcribe("message", 1000, chatterCallback);
  return 0;


rosed chapter2_tutorials CMakeLists.txt

cmake_minimum_required(VERSION 2.4.6)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)


#set the default path for built executables to the "bin" directory
#set the default path for built libraries to the "lib" directory

#uncomment if you have defined messages
#uncomment if you have defined services

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})

rosbuild_add_executable(example1_a src/example1_a.cpp)
rosbuild_add_executable(example1_b src/example1_b.cpp)

Making package:

kirill@kirill-Aspire-E1-571G:~/dev/rosbook/chapter2_tutorials$ rosmake chapter2_tutorials
[ rosmake ] rosmake starting...                                                                                                                 
[ rosmake ] Packages requested are: ['chapter2_tutorials']                                                                                      
[ rosmake ] Logging to directory /home/kirill/.ros/rosmake/rosmake_output-20140607-195627                                                       
[ rosmake ] Expanded args ['chapter2_tutorials'] to:
[rosmake-0] Starting >>> catkin [ make ]                                                                                                        
[rosmake-0] Finished <<< catkin ROS_NOBUILD in package catkin
 No Makefile in package catkin                                                    
[rosmake-0] Starting >>> genmsg [ make ]                                                                                                        
[rosmake-0] Finished <<< genmsg ROS_NOBUILD in package genmsg
 No Makefile in package genmsg                                                    
[rosmake-0] Starting >>> genlisp [ make ]                                                                                                       
[rosmake-1] Starting >>> genpy [ make ]                                                                                                         
[rosmake-0] Finished <<< genlisp ROS_NOBUILD in package genlisp
 No Makefile in package genlisp                                                 
[rosmake-2] Starting >>> gencpp [ make ]                                                                                                        
[rosmake-0] Starting >>> console_bridge [ make ]                                                                                                
[rosmake-3] Starting >>> rospack [ make ]                                                                                                       
[rosmake-3] Finished <<< rospack ROS_NOBUILD in package rospack
 No Makefile in package rospack                                                 
[rosmake-1] Finished <<< genpy ROS_NOBUILD in package genpy
 No Makefile in package genpy                                                       
[rosmake-2] Finished <<< gencpp ROS_NOBUILD in package gencpp
 No Makefile in package gencpp                                                    
[rosmake-3] Starting >>> roslib [ make ]                                                                                                        
[rosmake-2] Starting >>> message_generation [ make ]                                                                                            
[rosmake-1] Starting >>> roslang [ make ]                                                                                                       
[rosmake-0] Finished <<< console_bridge ROS_NOBUILD in package console_bridge
 No Makefile in package console_bridge                            
[rosmake-0] Starting >>> cpp_common [ make ]                                                                                                    
[rosmake-2] Finished <<< message_generation ROS_NOBUILD in package message_generation
 No Makefile in package message_generation                
[rosmake-2] Starting >>> rosgraph [ make ]                                                                                                      
[rosmake-1] Finished <<< roslang ROS_NOBUILD in ...
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-06-07 11:32:06 -0500

dornhege gravatar image

ros::init not ros::Init.

edit flag offensive delete link more


hi, dornhege! Yeah, you are right. I should to code with more care and attention. There were a several errors with literal errors. This resource was helpful for me - Or we can just google this "class ros::NodeHandle" to found out members with right case sensitive. Thanks! Regards, Kirill.

Kirill gravatar image Kirill  ( 2014-06-07 18:33:31 -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


Asked: 2014-06-07 11:09:52 -0500

Seen: 2,565 times

Last updated: Jun 07 '14