Compile error: ‘Init’ is not a member of ‘ros’
Ubuntu 12.04, ROS Hydro
Workspace:
$ echo $ROS_PACKAGE_PATH
/home/kirill/dev/rosbook:/opt/ros/hydro/share:/opt/ros/hydro/stacks
Created ROS pack:
roscd chapter2_tutorials/src/
ls
bin build CMakeLists.txt include lib mainpage.dox Makefile manifest.xml src
Test ROS Package has two source files:
cd src
ls
example1_a.cpp example1_b.cpp
example1_a.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 ";
msg.data = ss.str();
//
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
example1_b.cpp:
#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);
ros::spin();
return 0;
}
CMakeLists.txt:
rosed chapter2_tutorials CMakeLists.txt
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# 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)
rosbuild_init()
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()
#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#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:
['chapter2_tutorials']
[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 ...