ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Is there a C++ equivalent to roslib.get_ros_home() ?

asked 2014-02-09 05:23:09 -0600

ahendrix gravatar image

updated 2016-10-24 09:01:11 -0600

ngrennan gravatar image

In python, it's possible to use roslib.get_ros_home() to query the environment for the ROS_HOME environment variable, and fall back to HOME/.ros if it doesn't exist. This is very useful for finding a directory that ROS processes can use for storing their own logs or other temporary data.

Is there any equivalent to this in C++?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-02-09 16:21:02 -0600

Hi there!

Inside roscpp/src/libros/file_log.cpp they use:

std::string ros_log_env;
get_environment_variable(ros_log_env, "ROS_HOME")

But I wasn't able to figure out where get_environment_variable comes from (is it a system call? is it a custom fucntion?... no idea).

I hope this hint would help you

edit flag offensive delete link more



Thanks! I suspect the get_environment_variable uses the standard C `getenv` function somewhere underneath. Looking into file_log.cpp some more, it looks like they're implementing the fallback logic by hand rather than using a library function for it. I suspect I'll have to do the same in my code.

ahendrix gravatar image ahendrix  ( 2014-02-09 16:49:10 -0600 )edit
Daniel Stonier gravatar image Daniel Stonier  ( 2014-08-30 08:08:36 -0600 )edit

Hi Daniel, thanks for pointing that out! Could you, please, check the link that you posted? It currently points to instead of the file that you mention. Thanks!

Martin Peris gravatar image Martin Peris  ( 2014-08-31 21:47:06 -0600 )edit

Question Tools



Asked: 2014-02-09 05:23:09 -0600

Seen: 575 times

Last updated: Feb 09 '14