Ask Your Question

Compile source code in another package

asked 2012-11-25 14:43:52 -0500

I would like to compile the source files in package A as part of package B (i.e. not create a library from A and link it to B). Package A was written in such a way that various compiler flags can be passed in for various target installations. One solution is to create multiple libraries. This was discussed in this question, but this is problematic since there are multiple compiler options. Is there any way within the rosbuild system (or catkin) to do this.

It looks like CMake allows for this with an auxiliary source function. This could be used with rosbuild find ros package function. However, this is not recommended by CMake since it might require recompiling package A every time, or worse, missing changes in package A.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-11-26 04:39:05 -0500

joq gravatar image

updated 2012-11-26 04:44:08 -0500

An ugly solution is to export the package A sources as C++ header files, which could be compiled in B as a separate library using the desired CFLAGS.

I can think of reasons not to do it that way. Some of them might be mitigated by placing the headers in an impl subdirectory, referenced like this:

#include <A/impl/lib_sources.hpp>

If I were actually going to maintain some code this way, I might prefer creating a separate package for the header files which both A and B could use as needed.

edit flag offensive delete link more


That is ugly...but it seems there aren't any better options. The "rosbuild_find_ros_package" macro in my original question doesn't exist under catkin so that's not really an option.

sedwards gravatar image sedwards  ( 2012-11-27 15:25:39 -0500 )edit

There must be other options. Maybe some are better. But, this ugly one depends only on ordinary C++ language features and header resolution, making it somewhat portable.

joq gravatar image joq  ( 2012-11-28 03:32:37 -0500 )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


Asked: 2012-11-25 14:43:52 -0500

Seen: 121 times

Last updated: Nov 26 '12