我正在尝试组合两个CMakeLists.txt文件来编译一个同时具有ROS和Libtorch依赖项的C++程序。下面提供了各个文件:
Libtorch CMakeLists.txt文件:
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文件:
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两个库。
所以这是我想要做的:
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头文件:
#include "ros/ros.h"
#include <torch/torch.h>
.
.
.但是,我得到了以下错误。
fatal error: torch/torch.h: No such file or directory
#include <torch/torch.h>
^~~~~~~~~~~~~~~
compilation terminated.有人能帮帮我吗??
非常感谢。
发布于 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的人有帮助:)
https://stackoverflow.com/questions/61438764
复制相似问题