Ask Your Question
0

Including ros into scons project

asked 2018-08-22 14:40:30 -0600

alsora gravatar image

updated 2018-08-23 13:38:07 -0600

Hi,

I have built ros from sources (specifically ros2 bouncy bolson). The result is that I have a workspace containing all the header and lib files.

Now I would like to write a ros node inside a project which is built using Scons. How should I include and link properly all the required stuffs?

My program is just an hello world which includes the C++ client library

#include <iostream>
#include "rclcpp/rclcpp.hpp"

int main(int argc, char* argv[])
{
  std::cout<<"Hello World!"<<std::endl;
  return 0;
}

Sconstruct file

 env = Environment()
 env.Append(CXXFLAGS = ['-std=c++14'])
 env.Append(CPPPATH = ['<PATH_TO_ROS2_WS>/install/rclcpp/include', .....])
 env.Append(LIB_PATH=['<PATH_TO_ROS2_WS>/install/rclcpp/lib', ....])
 env.Program("hello_ros", ["hello_ros.cpp"])

I tried to manually append one by one to the environment the path to ROS2 include dirs and library locations.

UPDATE: I was getting an error due to the CXXFLAGS set to c++11, ROS2 requires C++14.

Is there a way to let Scons find the ROS2 include and library files, instead of having to manually specify them (they are a lot if I'm not using the --merge-install flag during the ros2 build)?

Thanks

edit retag flag offensive close merge delete

Comments

When you say nothing is working, can you paste the error message? I guess it is a linkage error but maybe it is something different. You will need to include all libraries/includes from ROS2 (at least the one that RCLCPP depends on).

pokitoz gravatar imagepokitoz ( 2018-08-23 11:40:29 -0600 )edit
1

Hi, thanks for your help but I solved that error. I have still an issue due to the fact that I have to manually specify all the lib and include paths (they are a lot if I'm not using the --merge-install flag during the ros2 build)

alsora gravatar imagealsora ( 2018-08-23 12:34:27 -0600 )edit

I don't think there is another solution to adding all the lib/include paths to your build. (unfortunately :D)

pokitoz gravatar imagepokitoz ( 2018-08-24 05:27:28 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-08-24 11:20:25 -0600

Dirk Thomas gravatar image

I have no knowledge about scons, but the following might be helpful whatever you want to integrate ROS 2 packages into:

ament_cmake packages automatically generate CMake config files. You can query the information provided by those through the CMake command line tool.

The compiler arguments required to build against a specific ROS 2 can be queries with:

cmake --find-package -DNAME=rclcpp -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=COMPILE

The linker arguments can be retrieved with a similar command:

cmake --find-package -DNAME=rclcpp -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=LINK

If you depend on multiple package you will have to query the arguments for each of them.

edit flag offensive delete link more

Comments

Thanks! However it works with other packages (i.e. boost), but with rclcpp I get an error: Generator implementation error, all generators must specify this->FindMakeProgramFile CMake was unable to find a build program corresponding to "Generic" CMAKE_MAKE_PROGRAM is not set

alsora gravatar imagealsora ( 2018-08-24 11:36:48 -0600 )edit

The posted command lines do work for me on Ubuntu Bionic with a locally built workspace (haven't tried any other combinations but would expect them to work too).

Dirk Thomas gravatar imageDirk Thomas ( 2018-08-24 11:38:43 -0600 )edit

Ok thank you. I tested it on a Bionic Docker container and it works. The error is on Ubuntu Xenial

alsora gravatar imagealsora ( 2018-08-24 11:47:12 -0600 )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

2 followers

Stats

Asked: 2018-08-22 14:40:30 -0600

Seen: 95 times

Last updated: Aug 24 '18