Compile roscpp without ros (using g++)

2019-02-25 14:14发布

I'm trying to compile roscpp without using the rest of ROS (I only need to subscribe to a node but the one that own that uses an old version of ROS and I couldn't integrate my program with his due to compilation troubles). I downloaded the source code from git (https://github.com/ros/ros_comm) and now I need to compile it, but Cmake throw me errors:

 INFOBuilding GTest from source.
 TODO: implement add_roslaunch_check() in rostest-extras.cmake.
 CMake Error at CMakeLists.txt:8 (catkin_package_xml):
     Unknown CMake command "catkin_package_xml".

How can I build it? I'm calling cmake CMakeList.txt, but it doesn't work.

标签: c++ ros
2条回答
看我几分像从前
2楼-- · 2019-02-25 15:06

Use this command line to compile your code directly with g++:

g++ yourtest.cpp -o yourtest -I/opt/ros/indigo/include -L/opt/ros/indigo/lib \
-Wl,-rpath,/opt/ros/indigo/lib -lroscpp -lrosconsole -lrostime \
-lroscpp_serialization -lboost_system -lboost_thread -pthread -lactionlib

Where yourtest.cpp is your c++ file that has some ros code.

If you are using a ros version different of the indigo replace de indigo string by the string of your version.

查看更多
Lonely孤独者°
3楼-- · 2019-02-25 15:12

I suggest you to use rosinstall_generator to compile the package you want, such as roscpp. Here are the steps:

Download the package and its dependencies:

rosinstall_generator roscpp --rosdistro <ROS_Distro that you use> --deps > roscpp_ros.rosinstall
wstool init src roscpp_ros.rosinstall -j8
rosdep install --from-path src -i -y

Then compile it:

src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release

The compiled packages will be in the folder install_isolated (at the same level as the folder src)

查看更多
登录 后发表回答