I have a project using libtorch and we need wrapper it into a ros package. nightmare comes:
we have no problem to build executable program without ros. But when using is along with catkin:
set(CMAKE_PREFIX_PATH $ENV{HOME}/libtorch)
find_package(Torch REQUIRED)
include_directories(include/)
#include_directories("$ENV{HOME}/libtorch/include/")
#include_directories("$ENV{HOME}/libtorch/include/torch/csrc/api/include")
if (NOT Torch_FOUND)
message(FATAL_ERROR "libtorch not found, wavehands_stop will not built.")
else ()
message(STATUS "++++ found libtorch ")
It will wipe out catkin libs and throw out undefined ros::inti blabla errors, I dont know why.
And even torch was found, it still can not found torch/torch.h header file:
I am currently have some thoughts on this but I can not solve the problem, kindly want community give me some help!!
- it was caused by libtorch CMAKE_PREFIX_PATH I think, this variable can not get along with catkin, since found torch need this, I can not delete it;
- I can not manually set header path point to torch/torch.h, it cause a lot of warnings and even undefined errors even I link TORCH_LIBRARIES.
Here is my cmakelists in ROS:
cmake_minimum_required(VERSION 2.8.3)
project(ws_stop)
add_definitions("-std=c++11")
find_package(catkin REQUIRED COMPONENTS
roscpp
pcl_conversions
pcl_ros
sensor_msgs
geometry_msgs
message_filters
tf_conversions
tf
laser_geometry
cv_bridge
std_msgs
message_generation)
find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)
catkin_package(
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${OpenCV_INCLUDE_DIRS}
# ${PCL_INCLUDE_DIRS}
)
# !---------------] find libs what wavehands need
set(CMAKE_PREFIX_PATH $ENV{HOME}/libtorch)
find_package(Torch REQUIRED)
include_directories(include/)
#include_directories("$ENV{HOME}/libtorch/include/")
#include_directories("$ENV{HOME}/libtorch/include/torch/csrc/api/include")
if (NOT Torch_FOUND)
message(FATAL_ERROR "libtorch not found, will not built.")
else ()
message(STATUS "++++ found libtorch ")
find_library(HUMAN_POSE_ESTIMATION
NAMES human_pose_estimation
HINTS ./libs
PATHS ./libs)
file(GLOB_RECURSE
SOURCES
src/*.cc)
add_executable(w_stop_node ${SOURCES})
target_link_libraries(
wavehands_stop_node
${catkin_LIBRARIES}
# ${TORCH_LIBRARIES}
# torch
# c10
# ${HUMAN_POSE_ESTIMATION}
)
get_target_property(TARGET_LIBRARIES w_stop_node LINK_LIBRARIES)
message(STATUS ${TARGET_LIBRARIES})
endif ()
Any one could give a indicates or sample cmakelists which can link libtorch correctly in ros??