首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >合并两个CMakeLists.txt文件(ROS和Libtorch)

合并两个CMakeLists.txt文件(ROS和Libtorch)
EN

Stack Overflow用户
提问于 2020-04-26 17:50:27
回答 1查看 441关注 0票数 1

我正在尝试组合两个CMakeLists.txt文件来编译一个同时具有ROS和Libtorch依赖项的C++程序。下面提供了各个文件:

Libtorch CMakeLists.txt文件:

代码语言:javascript
复制
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)

find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
  file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
  add_custom_command(TARGET example-app
                     POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E copy_if_different
                     ${TORCH_DLLS}
                     $<TARGET_FILE_DIR:example-app>)
endif (MSVC)

我在这里找到了这个:https://pytorch.org/cppdocs/installing.html

ROS CMakeListis.txt文件:

代码语言:javascript
复制
cmake_minimum_required(VERSION 2.8.3)
project(fly_bot_cpp)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  geometry_msgs
  tf
  gazebo_msgs
)

include_directories(
 include
  ${catkin_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
)

add_executable(example src/example.cpp)
target_link_libraries(example ${catkin_LIBRARIES})

程序example-app.cpp包含ROS和LibTorch两个库。

所以这是我想要做的:

代码语言:javascript
复制
cmake_minimum_required(VERSION 2.8.3)
project(fly_bot_cpp)

set(CMAKE_PREFIX_PATH="home/jarvis/libtorch;/opt/ros/melodic")

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  geometry_msgs
  tf
  rospy
  message_generation
)

find_package(Torch REQUIRED)

include_directories(
 include
  ${catkin_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
)

add_executable(test_quad src/test_quad.cpp)
target_link_libraries(test_quad ${catkin_LIBRARIES} "${TORCH_LIBRARIES}")

set_property(TARGET test_quad PROPERTY CXX_STANDARD 14)

代码test_quad.cpp (以前称为example-app.cpp)包含ros头文件和torch头文件:

代码语言:javascript
复制
#include "ros/ros.h"
#include <torch/torch.h>
.
.
.

但是,我得到了以下错误。

代码语言:javascript
复制
fatal error: torch/torch.h: No such file or directory
 #include <torch/torch.h>
          ^~~~~~~~~~~~~~~
compilation terminated.

有人能帮帮我吗??

非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2020-12-17 08:38:57

删除target_link_libraries中${TORCH_LIBRARIES}周围的引号。这条线应该看起来像这样

target_link_libraries(test_quad ${catkin_LIBRARIES} ${TORCH_LIBRARIES})

这应该会解析火炬头部。

也请看看这篇文章,找到更多关于你未来可能陷入困境的答案--https://answers.ros.org/question/347885/combining-cmakeliststxt-of-libtorch-and-cmakeliststxt-of-ros-package/#

我希望这个答案对那些刚开始接触ros和libtorch的人有帮助:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61438764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档