gpt4 book ai didi

c++ - 将 Catkin 与 CMake 接口(interface)库一起使用

转载 作者:行者123 更新时间:2023-11-30 04:55:05 26 4
gpt4 key购买 nike

我目前正在尝试使用在 catkin 中声明为 cmake 接口(interface)库的仅包含 c++ header 的库。这个库应该被 catkin_ws/src 中的其他包使用。我能够使用 catkin_make 编译所有包,但不能使用 catkin build

catkin build 在依赖包中的 cmake 命令 find_package(... interface_lib) 中失败。

以下示例的错误消息为:

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?

我需要如何设置 CMakeLists.txtpackage.xml 文件才能使 catkin build 与接口(interface)库一起工作?

最小示例:

接口(interface)库

文件:catkin_ws/src/interface_library/include/interface_library.hpp

#pragma once

#define RATE 10

文件: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)

文件: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="master@disaster.com">Master of Disaster</maintainer>
<license>MIT</license>
<buildtool_depend>catkin</buildtool_depend>
</package>

测试节点

文件:catkin_ws/src/testnode/src/testnode.cpp

#include <iostream>
#include "interface_library.hpp"

int main(void)
{
std::cout << RATE << std::endl;
}

文件: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)

文件: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="master@disaster.com">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>

最佳答案

我刚遇到这个问题。解决方法是从文件 interface_library/CMakeLists.txt 中的 catkin_package 中删除行 LIBRARIES ${PROJECT_NAME}

This answer 提到 LIBRARIES 行要求您实际构建一个目标(并且 the documentation 说如果目标名称与已安装的名称不对应,它目前会中断),所以我猜只是目前不是为处理接口(interface)库而编写的。

关于c++ - 将 Catkin 与 CMake 接口(interface)库一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53267571/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com