[英]ROS rosmake error
I am currently working on a project with ROS. 我目前正在与ROS合作进行项目。 I am completely new to ROS and it's features. 我对ROS及其功能完全陌生。 Currently i'm doing a tutorial on ROS and started using code for the first time. 目前,我正在编写有关ROS的教程,并且是第一次开始使用代码。 although i do have some experience with c++, i can't figure out what is going wrong. 尽管我确实有使用c ++的经验,但我不知道出了什么问题。 In ROS i use the rosmake command and it fails to compile the cpp file/code. 在ROS中,我使用rosmake命令,但无法编译cpp文件/代码。 Can anyone help me figure out why the error occurs? 谁能帮助我找出错误发生的原因? (and possibly how to fix it?) (以及可能如何解决?)
below is the cpp file code: 以下是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 example1_a node ";
msg.data = ss.str();
//ROS_INFO("%s", msg.data.c_str());
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
And here the build log: 这里是构建日志:
mkdir -p bin
cd build && cmake -Wdev -DCMAKE_TOOLCHAIN_FILE=/opt/ros/indigo/share/ros/core/rosbuild/rostoolchain.cmake ..
[rosbuild] Building package chapter2_tutorials
[rosbuild] using multiarch 'x86_64-linux-gnu' for finding Boost
-- Using CATKIN_DEVEL_PREFIX: /home/rospc/dev/rosbook/chapter2_tutorials/build/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/indigo
-- This workspace overlays: /opt/ros/indigo
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Skip enable_testing() for dry packages
-- Using CATKIN_TEST_RESULTS_DIR: /home/rospc/dev/rosbook/chapter2_tutorials/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.16
-- Using these message generators: gencpp;genlisp;genpy
[rosbuild] Including /opt/ros/indigo/share/roslisp/rosbuild/roslisp.cmake
[rosbuild] Including /opt/ros/indigo/share/roscpp/rosbuild/roscpp.cmake
[rosbuild] Including /opt/ros/indigo/share/rospy/rosbuild/rospy.cmake
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rospc/dev/rosbook/chapter2_tutorials/build
cd build && make -j8 -l8
make[1]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[2]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
[ 0%] Built target rospack_genmsg_libexe
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
[ 0%] Built target rosbuild_precompile
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
Scanning dependencies of target example1_a
Scanning dependencies of target example1_b
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
[100%] [100%] Building CXX object CMakeFiles/example1_b.dir/src/example1_b.cpp.o
Building CXX object CMakeFiles/example1_a.dir/src/example1_a.cpp.o
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp: In function ‘int main(int, char**)’:
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:8:42: error: ‘std_’ was not declared in this scope
ros::Publisher chatter_pub = n.advertise<std_
^
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:8:32: error: parse error in template argument list
ros::Publisher chatter_pub = n.advertise<std_
^
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: no matching function for call to ‘ros::NodeHandle::advertise(const char [8], int)’
msgs::String>("message", 1000);
^
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: note: candidates are:
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
from /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:1:
/opt/ros/indigo/include/ros/node_handle.h:236:15: note: template<class M> ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, bool)
Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false)
^
/opt/ros/indigo/include/ros/node_handle.h:236:15: note: template argument deduction/substitution failed:
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: template argument 1 is invalid
msgs::String>("message", 1000);
^
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
from /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:1:
/opt/ros/indigo/include/ros/node_handle.h:302:13: note: template<class M> ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, const SubscriberStatusCallback&, const SubscriberStatusCallback&, const VoidConstPtr&, bool)
Publisher advertise(const std::string& topic, uint32_t queue_size,
^
/opt/ros/indigo/include/ros/node_handle.h:302:13: note: template argument deduction/substitution failed:
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: template argument 1 is invalid
msgs::String>("message", 1000);
^
make[3]: *** [CMakeFiles/example1_a.dir/src/example1_a.cpp.o] Error 1
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[2]: *** [CMakeFiles/example1_a.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
Linking CXX executable ../bin/example1_b
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
[100%] Built target example1_b
make[2]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make: *** [all] Error 2
This next code is from the second file, which does compile and creates no errors: 接下来的代码来自第二个文件,该文件会编译并且不会产生任何错误:
#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.subscribe("message", 1000, chatterCallback);
ros::spin();
return 0;
}
Line breaks in C++ code can only be done in 3 ways : C ++代码中的换行符只能通过3种方式完成:
cout<<"Error:This is a really long error "
"message that exceeds the maximum permitted length.\n";
or 要么
cout<<"Error:This is a really long error \
message that exceeds the maximum permitted length.\n";
or 要么
c\
o\
u\
t<<"Error:This is a really long error \
message that exceeds the maximum permitted length.\n";
other than that, it will throw you errors ... 除此之外,它还会引发错误...
Change: 更改:
ros::Publisher chatter_pub = n.advertise<std_
msgs::String>("message", 1000);
By: 通过:
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("message", 1000);
PS : You should not use rosmake . PS: 您不应该使用rosmake 。 It's an old tool to build your workspace. 这是用于构建工作区的旧工具。
Use catkin_make
or catkin build
. 使用 catkin_make
或catkin_make
catkin build
。
Note: You can't use both catkin_make and catkin build on the same workspace. 注意:不能在同一工作空间上同时使用catkin_make和catkin 构建 。 If you want to switch you need to clean your workspace. 如果要切换,则需要清理工作区。 For that it's easy, you have to erase your build, devel and install directory in your workspace folder. 为此,您必须删除工作区文件夹中的构建,开发和安装目录。
$ cd ~/catkin_ws
$ sudo rm -r devel build install
Alternative ways : 替代方式:
If you use catkin_make and want to clean your workspace to switch to catkin build use 如果您使用catkin_make并希望清理工作区以切换到catkin构建使用
$ catkin_make clean
$ catkin build
If you use catkin build and want to clean your workspace to switch to catkin_make use 如果您使用catkin build并希望清理工作区以切换到catkin_make使用
$ catkin clean
$ catkin_make
rosmake vs catkin: 罗斯马克vs卡特金:
Since ROS Groovy, it's not recommended to use rosmake, here is why we use catkin: 由于ROS Groovy,因此不建议使用rosmake,这就是为什么我们使用柔cat花色的原因:
catkin_make vs catkin build : catkin_make vs catkin build :
Quite the same, but the most recent catkin build . 差不多,但最新的柔kin花序 。 Nowadays, some people recommend to switch from catkin_make to catkin build . 如今,有人建议从catkin_make切换到catkin build 。 The main difference between both is that catkin build has a better isolation package. 两者之间的主要区别在于,catkin构建具有更好的隔离包。 It will build each package a workspace. 它将为每个包构建一个工作区。
Use C++11 for make your project. 使用C ++ 11制作项目。 For this use the cmake flag in your command: 为此,请在命令中使用cmake标志:
catkin_make -DCMAKE_CXX_FLAGS=-std=c++11
Or 要么
catkin build -DCMAKE_CXX_FLAGS=-std=c++11
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.