簡體   English   中英

ROS rosmake錯誤

[英]ROS rosmake error

我目前正在與ROS合作進行項目。 我對ROS及其功能完全陌生。 目前,我正在編寫有關ROS的教程,並且是第一次開始使用代碼。 盡管我確實有使用c ++的經驗,但我不知道出了什么問題。 在ROS中,我使用rosmake命令,但無法編譯cpp文件/代碼。 誰能幫助我找出錯誤發生的原因? (以及可能如何解決?)

以下是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;
}

這里是構建日志:

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

接下來的代碼來自第二個文件,該文件會編譯並且不會產生任何錯誤:

#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;
}

C ++代碼中的換行符只能通過3種方式完成:

cout<<"Error:This is a really long error "
"message that exceeds the maximum permitted length.\n";

要么

cout<<"Error:This is a really long error \
message that exceeds the maximum permitted length.\n";

要么

c\
o\
u\
t<<"Error:This is a really long error \
message that exceeds the maximum permitted length.\n";

除此之外,它還會引發錯誤...

更改:

ros::Publisher chatter_pub = n.advertise<std_
msgs::String>("message", 1000);

通過:

ros::Publisher chatter_pub = n.advertise<std_msgs::String>("message", 1000);

PS: 您不應該使用rosmake 這是用於構建工作區的舊工具。

使用 catkin_makecatkin_make catkin build

注意:不能在同一工作空間上同時使用catkin_makecatkin 構建 如果要切換,則需要清理工作區。 為此,您必須刪除工作區文件夾中的構建,開發和安裝目錄。

$ cd ~/catkin_ws
$ sudo rm -r devel build install

替代方式:

如果您使用catkin_make並希望清理工作區以切換到catkin構建使用

$ catkin_make clean
$ catkin build

如果您使用catkin build並希望清理工作區以切換到catkin_make使用

$ catkin clean
$ catkin_make

羅斯馬克vs卡特金:

由於ROS Groovy,因此不建議使用rosmake,這就是為什么我們使用柔cat花色的原因:

  • 更好地利用Cmake提供的所有工具,
  • Cmake的C表示跨平台。 這樣做的目的是使ROS在不同的體系結構(ARM)和OS(OS X和Windows)上更具可移植性。
  • 使用rosbuild時,每個程序包都有自己的Cmake,程序包依賴性管理不穩定。
  • 通過並行化依賴關系,Cmake可以更智能地進行編譯。
  • 通過優化依賴關系來減少內存空間。
  • 一個單一的安裝目標,使公司可以在ROS上運行封閉的專有軟件。

catkin_make vs catkin build

差不多,但最新的柔kin花序 如今,有人建議從catkin_make切換到catkin build 兩者之間的主要區別在於,catkin構建具有更好的隔離包。 它將為每個包構建一個工作區。

使用C ++ 11制作項目。 為此,請在命令中使用cmake標志:

catkin_make -DCMAKE_CXX_FLAGS=-std=c++11

要么

catkin build -DCMAKE_CXX_FLAGS=-std=c++11

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM