Reputation: 41
I am currently trying to use a c++ header-only library declared as a cmake interface library within catkin. This library is supposed to be used by other packages in catkin_ws/src. I was able to compile all packages with catkin_make
but not with catkin build
.
catkin build
fails within the cmake command find_package(... interface_lib)
in dependent packages.
Error-Message for the example below would be:
Project 'testnode' tried to find library 'interface_library'. The library is neither a target nor built/installed properly. Did you compile project 'interface_library'? Did you find_package() it before the subdirectory containing its code is included?
How do i need to setup CMakeLists.txt and package.xml files to make catkin build
work with interface libraries?
File: catkin_ws/src/interface_library/include/interface_library.hpp
#pragma once
#define RATE 10
File: catkin_ws/src/interface_library/CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(interface_library)
find_package(catkin REQUIRED)
catkin_package(INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME})
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE include)
File: catkin_ws/src/interface_library/package.xml
<package format="2">
<name>interface_library</name>
<description>Test interface library</description>
<version>0.0.1</version>
<maintainer email="[email protected]">Master of Disaster</maintainer>
<license>MIT</license>
<buildtool_depend>catkin</buildtool_depend>
</package>
File: catkin_ws/src/testnode/src/testnode.cpp
#include <iostream>
#include "interface_library.hpp"
int main(void)
{
std::cout << RATE << std::endl;
}
File: catkin_ws/src/testnode/CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(testnode)
find_package(catkin REQUIRED COMPONENTS interface_library)
catkin_package()
include_directories(${catkin_INCLUDE_DIRS})
add_executable(${PROJECT_NAME}_node src/testnode.cpp)
File: catkin_ws/src/testnode/package.xml
<?xml version="1.0"?>
<package format="2">
<name>testnode</name>
<version>0.0.0</version>
<description>The testnode package</description>
<maintainer email="[email protected]">Master of Disaster</maintainer>
<license>MIT</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>interface_library</build_depend>
<build_export_depend>interface_library</build_export_depend>
<exec_depend>interface_library</exec_depend>
</package>
Upvotes: 2
Views: 4346
Reputation: 56
I've just come across this problem. The fix was to remove the line LIBRARIES ${PROJECT_NAME}
from catkin_package
in the file interface_library/CMakeLists.txt.
This answer mentions that the LIBRARIES
line requires that you're actually building a target (and the documentation says it currently breaks if the target name doesn't correspond to an installed name), so I guess it just isn't currently written to deal with interface libraries.
Upvotes: 4
Reputation: 574
older catkin or catkin_make
uses merged development space but newer catkin or catkin build
use linked development space by default.
First thing you should do is to separate catkin workspaces from each other in 2 different folder. Then set up change catkin build
's workspace to merged-devel with:
catkin config --merge-devel
and also manually expand it's search areas to both your main ROS folder (default in /opt/ros/<your-version>
) and other catkin workspaces which you may use with:
catkin config --expand <path-to-ros-workspace>
after that add your projects and build.
Upvotes: 0