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

CMake Functions work with 'catkin_make' but fail with 'catkin build

asked 2019-04-10 13:10:33 -0500

Spencer Fishman gravatar image

updated 2019-04-11 09:29:27 -0500

I have two catkin packages. One package will be called 'function_maker' and the other is 'function_user'. Here are my two CMakeLists.txt:

function_maker CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(function_maker)
add_compile_options(-std=c++11 -g)

find_package(catkin REQUIRED)

catkin_package()

function(test_func arg)
    message("Function Called")
endfunction()

function_user CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(function_user)
add_compile_options(-std=c++11 -g)

find_package(catkin REQUIRED
    COMPONENTS
        function_maker
)

catkin_package()

test_func()

When I use 'catkin_make' to build my workspace, everything works as expected and during the build process I see a message that says "Function Called".

However, when I use 'catkin build' to build my workspace, I get the following error message:

Unknown CMake command "test_func".

Why is there a difference between 'catkin_make' and 'catkin build'? How can I make this work with both build tools?

edit retag flag offensive close merge delete

Comments

find_package(catkin REQUIRED
    COMPONENETS
        function_maker

is this a copy-pasta? COMPONENETS is not a recognised argument to find_package(..).

gvdhoorn gravatar image gvdhoorn  ( 2019-04-10 14:05:22 -0500 )edit

Please read https://catkin-tools.readthedocs.io/e... which describes the differences.

Dirk Thomas gravatar image Dirk Thomas  ( 2019-04-10 14:07:10 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-04-10 14:13:54 -0500

gvdhoorn gravatar image

updated 2019-04-10 14:21:17 -0500

The most likely reason is that catkin_make coalesces all projects (ie: ROS packages) into a single build (equivalent to calling add_subdirectory(..)) whereas catkin_tools (which supplies the catkin command) builds all packages in isolation.

(Edit: including @Dirk Thomas' comment) Refer to Migrating from catkin_make in the catkin_tools documentation for more information on the differences between catkin_make and catkin_tools.

When I use 'catkin_make' to build my workspace, everything works as expected and during the build process I see a message that says "Function Called".

However, when I use 'catkin build' to build my workspace, I get the following error message:

So with catkin_make, test_func() is defined (and declared) in the same build context, while with catkin_tools, test_func() only exists within the context in which function_maker is processed.

This leads to test_func() being an unknown symbol in the latter case, hence the error message.

How can I make this work with both build tools?

One approach could be to use the CFG_EXTRAS argument of the catkin_package(..) macro (documentation).

This would allow you to export the function in such a way that its definition (and declaration) are imported into the build context of function_user, provided function_user properly find_package(..)s function_maker.

There are various Q&As on ROS Answers about this, see #q173947, #q173683, #q93266 and #q275318 for instance.

edit flag offensive delete link more

Comments

I will be testing this out today and will do so. Thank you for your help

Spencer Fishman gravatar image Spencer Fishman  ( 2019-04-11 09:23:54 -0500 )edit

@gvdhoorn I thought I had this working, but went to catkin build today and I am running into an issue. The CFG_EXTRAS cmake file I created seems to not have access to some CMAKE variables. Specifically, the .cmake.in file thinks that ${function_maker_SOURCE_DIR} is an empty string. The reason I need this, is because "test_func" really uses some python scripts in ${function_maker_SOURCE_DIR}/src to generate headers from an XML file. Any idea how I can solve this?

Spencer Fishman gravatar image Spencer Fishman  ( 2019-04-20 16:43:35 -0500 )edit

@gvdhoorn I ended up printing all defined cmake variables and found that instead of SOURCE_DIR, the extra cmake files defined the path as SOURCE_PREFIX. Was this documented? I am very unfamiliar with cmake, so maybe I should have known this.

Spencer Fishman gravatar image Spencer Fishman  ( 2019-04-20 17:01:18 -0500 )edit

Question Tools

Stats

Asked: 2019-04-10 13:10:33 -0500

Seen: 1,401 times

Last updated: Apr 11 '19