0
$\begingroup$

Rosanswers logo

Folks,

I have some variables I declared in my CMakeList in one package. For example, I create the constant:

add_definitions(-DTRAINED_DATA_PATH="${PROJECT_SOURCE_DIR}/trained_data")

How can I make it available to other ROS packages?


Originally posted by Pototo on ROS Answers with karma: 803 on 2016-09-02

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You'll want to look into Catkin's CFG_EXTRA feature.

See How to export non-standard include directories in catkin? for an answer by @William that explains how to do this (this deals with include directories specifically, but the principle is the same. Just place an add_definitions(..) in your extras file, and be careful with PROJECT_SOURCE_DIR, as it may not have the same value (or be even defined) in the devel and install spaces).

Btw: using (ROS) parameters is a bit more flexible than using hard-coded, compile time constants, as it allows you to specify the location of things using a bit of configuration. That would also remove the need for exporting the define. If you have the option (ie: this is not a completely stand-alone library that is supposed to work without ROS), I'd use that.


Originally posted by gvdhoorn with karma: 86574 on 2016-09-04

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Pototo on 2016-09-09:
I agree with the parameters suggestions. That will avoid recompilation every time

Comment by Pototo on 2016-09-12:
Actually, how do you create this in a config file by using appropriate project paths?

Comment by gvdhoorn on 2016-09-13:
The answer by @William I linked should show you an example.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.