Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libtorch] Catkin_make compilation error #14352

Open
cindycia opened this issue Nov 25, 2018 · 8 comments
Open

[libtorch] Catkin_make compilation error #14352

cindycia opened this issue Nov 25, 2018 · 8 comments
Labels
has workaround module: build Build system issues needs reproduction Someone else needs to try reproducing the issue given the instructions. No action needed from user triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@cindycia
Copy link

cindycia commented Nov 25, 2018

I am trying to use libtorch to my catkin project.

One of my package A links with libtorch.so and can be successfually compiled as a static library A.a.

Then I try to linked A.a to another package B.

When I run catkin_make, the following error comes out:

-- Configuring done
CMake Error:
Error evaluating generator expression:

$<TARGET_PROPERTY:caffe2,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>

Target "caffe2" not found.

CMake Error:
Error evaluating generator expression:

$<TARGET_PROPERTY:caffe2_gpu,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>

Target "caffe2_gpu" not found.

CMake Error:
Error evaluating generator expression:

$<TARGET_PROPERTY:caffe2,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>

Target "caffe2" not found.

CMake Error:
Error evaluating generator expression:

$<TARGET_PROPERTY:caffe2_gpu,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>

Target "caffe2_gpu" not found.

-- Generating done
-- Build files have been written to: /home/panpan/workspace/catkin_ws/build
Makefile:4460: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed

My CMakeLists.txt in package A contains something like

project(A CXX CUDA) 
find_package(Torch REQUIRED)
...
target_link_libraries("${PROJECT_NAME}" "${TORCH_LIBRARIES}")

And CMakeLists.txt in package B calls:

target_link_libraries(B
   ${catkin_LIBRARIES}
   A
)

The error comes during the cmake generation stage where the configuration is done but the compilation hasn't started yet.
Only package A in my catkin workspace is using libtorch.

System configuration:

  • Ubuntu 18.04
  • Cmake 3.12.4
  • CUDA 9.0.176
  • gcc g++ 5.5
  • libtorch 1.0.0.dev20181121
  • Catkin comes with ROS melodic

Originally posted by @cindycia in https://github.com/pytorch/pytorch/issue_comments#issuecomment-441210189

@cindycia
Copy link
Author

Turns out that I have to add
`find_package(Torch REQUIRED)
also in package B.

But Cmake will complain that caffe2 is added twice.
It only works after some changes in libtorch/share/cmake/Caffe2/public/utils.cmake:
change
add_library(${DST} INTERFACE)
to

if (NOT TARGET ${DST})
    add_library(${DST} INTERFACE)
endif()

@zou3519 zou3519 added the module: build Build system issues label Nov 26, 2018
@siddheshmhatre
Copy link

@cindycia Hi. I am trying to compile my ROS workspace along with libtorch and I face linking errors with ros when I add find_package(Torch REQUIRED) in my CMakeLists.txt . Did you face similar problems?

@sbergsma
Copy link

sbergsma commented Mar 28, 2019

I got the same error in a different situation. I solved it by moving "find_package(Torch REQUIRED)" into my top-level CMakeLists.txt. More details: I have src/ and test/ directories, and previously compiled all my src code into a static library, and then linked this library into my test executable. I got the above error when I had find_package(Torch REQUIRED) in src/CMakeLists.txt but not in test/CMakeLists.txt.

@dingxiaojing
Copy link

@siddheshmhatre Hi, I face the same problem as you, did you find how to solve it? Thanks!

@colesbury colesbury added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 15, 2019
@siddheshmhatre
Copy link

@siddheshmhatre Hi, I face the same problem as you, did you find how to solve it? Thanks!

Hey,
It was fixed by compiling libtorch from source using the same compiler as used in ROS

@ezyang ezyang added has workaround needs reproduction Someone else needs to try reproducing the issue given the instructions. No action needed from user labels May 15, 2019
@lucasjinreal
Copy link

I got totally opposite errors.

I can find libtorch, but once link it, it will wipe out catkin libs and got some undefined reference to ros::init(int&, char**, std::string const&, unsigned int)'` errors. Unlink libtorch, everything works fine.

my cmakelists:

cmake_minimum_required(VERSION 2.8.3)
project(_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)
#find_package(PCL REQUIRED)


catkin_package(
        #  INCLUDE_DIRS include
        #  LIBRARIES semantic_seg
        #  CATKIN_DEPENDS other_catkin_pkg
        #  DEPENDS system_lib
)

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)
message(STATUS "++++++ torch find path" ${CMAKE_PREFIX_PATH})
find_package(Torch REQUIRED)
include_directories(include/)
if (NOT Torch_FOUND)
    message(FATAL_ERROR "you should change CMAKE_PREFIX_PATH to libtorch dir")
else ()
    message(STATUS "found libtorch at " ${TORCH_LIBRARIES})
endif ()




add_executable(w_stop_node)
target_link_libraries(
        wstop_node
        ${catkin_LIBRARIES}
        ${TORCH_LIBRARIES}
        glog
        thor
)

@yjhdhr
Copy link

yjhdhr commented Aug 7, 2019

我完全相反的错误。

我可以找到libtorch,但是一旦链接它,就会消灭catkin libs并得到一些undefined reference to ros :: init(int&,char **,std :: string const&,unsigned int)'`errors。取消链接libtorch,一切正常。

我的cmakelists:

cmake_minimum_required(VERSION 2.8.3)
project(_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)
#find_package(PCL REQUIRED)


catkin_package(
        #  INCLUDE_DIRS include
        #  LIBRARIES semantic_seg
        #  CATKIN_DEPENDS other_catkin_pkg
        #  DEPENDS system_lib
)

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)
message(STATUS "++++++ torch find path" ${CMAKE_PREFIX_PATH})
find_package(Torch REQUIRED)
include_directories(include/)
if (NOT Torch_FOUND)
    message(FATAL_ERROR "you should change CMAKE_PREFIX_PATH to libtorch dir")
else ()
    message(STATUS "found libtorch at " ${TORCH_LIBRARIES})
endif ()




add_executable(w_stop_node)
target_link_libraries(
        wstop_node
        ${catkin_LIBRARIES}
        ${TORCH_LIBRARIES}
        glog
        thor
)

HI !!Have you solved this problem?

run_model.cpp:(.text+0xf2):undefined reference to ‘ros::init(int&, char**, std::string const&, unsigned int)’
collect2: error: ld returned 1 exit status
irosnet/CMakeFiles/run_model.dir/build.make:190: recipe for target '/home/yjhdhr/catkin_ws/devel/lib/irosnet/run_model' failed
make[2]: *** [/home/yjhdhr/catkin_ws/devel/lib/irosnet/run_model] Error 1
CMakeFiles/Makefile2:916: recipe for target 'irosnet/CMakeFiles/run_model.dir/all' failed
make[1]: *** [irosnet/CMakeFiles/run_model.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

I had exactly the same problem, and I was very anxious.And I sent you an email, I hope you can see it.

@maxwellfrom
Copy link

我完全相反的错误。
我可以找到libtorch,但是一旦链接它,就会消灭catkin libs并得到一些undefined reference to ros :: init(int&,char **,std :: string const&,unsigned int)'`errors。取消链接libtorch,一切正常。
我的cmakelists:

cmake_minimum_required(VERSION 2.8.3)
project(_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)
#find_package(PCL REQUIRED)


catkin_package(
        #  INCLUDE_DIRS include
        #  LIBRARIES semantic_seg
        #  CATKIN_DEPENDS other_catkin_pkg
        #  DEPENDS system_lib
)

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)
message(STATUS "++++++ torch find path" ${CMAKE_PREFIX_PATH})
find_package(Torch REQUIRED)
include_directories(include/)
if (NOT Torch_FOUND)
    message(FATAL_ERROR "you should change CMAKE_PREFIX_PATH to libtorch dir")
else ()
    message(STATUS "found libtorch at " ${TORCH_LIBRARIES})
endif ()




add_executable(w_stop_node)
target_link_libraries(
        wstop_node
        ${catkin_LIBRARIES}
        ${TORCH_LIBRARIES}
        glog
        thor
)

HI !!Have you solved this problem?

run_model.cpp:(.text+0xf2):undefined reference to ‘ros::init(int&, char**, std::string const&, unsigned int)’
collect2: error: ld returned 1 exit status
irosnet/CMakeFiles/run_model.dir/build.make:190: recipe for target '/home/yjhdhr/catkin_ws/devel/lib/irosnet/run_model' failed
make[2]: *** [/home/yjhdhr/catkin_ws/devel/lib/irosnet/run_model] Error 1
CMakeFiles/Makefile2:916: recipe for target 'irosnet/CMakeFiles/run_model.dir/all' failed
make[1]: *** [irosnet/CMakeFiles/run_model.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

I had exactly the same problem, and I was very anxious.And I sent you an email, I hope you can see it.

Hi @

我完全相反的错误。
我可以找到libtorch,但是一旦链接它,就会消灭catkin libs并得到一些undefined reference to ros :: init(int&,char **,std :: string const&,unsigned int)'`errors。取消链接libtorch,一切正常。
我的cmakelists:

cmake_minimum_required(VERSION 2.8.3)
project(_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)
#find_package(PCL REQUIRED)


catkin_package(
        #  INCLUDE_DIRS include
        #  LIBRARIES semantic_seg
        #  CATKIN_DEPENDS other_catkin_pkg
        #  DEPENDS system_lib
)

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)
message(STATUS "++++++ torch find path" ${CMAKE_PREFIX_PATH})
find_package(Torch REQUIRED)
include_directories(include/)
if (NOT Torch_FOUND)
    message(FATAL_ERROR "you should change CMAKE_PREFIX_PATH to libtorch dir")
else ()
    message(STATUS "found libtorch at " ${TORCH_LIBRARIES})
endif ()




add_executable(w_stop_node)
target_link_libraries(
        wstop_node
        ${catkin_LIBRARIES}
        ${TORCH_LIBRARIES}
        glog
        thor
)

HI !!Have you solved this problem?

run_model.cpp:(.text+0xf2):undefined reference to ‘ros::init(int&, char**, std::string const&, unsigned int)’
collect2: error: ld returned 1 exit status
irosnet/CMakeFiles/run_model.dir/build.make:190: recipe for target '/home/yjhdhr/catkin_ws/devel/lib/irosnet/run_model' failed
make[2]: *** [/home/yjhdhr/catkin_ws/devel/lib/irosnet/run_model] Error 1
CMakeFiles/Makefile2:916: recipe for target 'irosnet/CMakeFiles/run_model.dir/all' failed
make[1]: *** [irosnet/CMakeFiles/run_model.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

I had exactly the same problem, and I was very anxious.And I sent you an email, I hope you can see it.

Hi ,Have you solved the problem? ,I met the same problem, looking forward to you help, thank you!

我完全相反的错误。
我可以找到libtorch,但是一旦链接它,就会消灭catkin libs并得到一些undefined reference to ros :: init(int&,char **,std :: string const&,unsigned int)'`errors。取消链接libtorch,一切正常。
我的cmakelists:

cmake_minimum_required(VERSION 2.8.3)
project(_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)
#find_package(PCL REQUIRED)


catkin_package(
        #  INCLUDE_DIRS include
        #  LIBRARIES semantic_seg
        #  CATKIN_DEPENDS other_catkin_pkg
        #  DEPENDS system_lib
)

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)
message(STATUS "++++++ torch find path" ${CMAKE_PREFIX_PATH})
find_package(Torch REQUIRED)
include_directories(include/)
if (NOT Torch_FOUND)
    message(FATAL_ERROR "you should change CMAKE_PREFIX_PATH to libtorch dir")
else ()
    message(STATUS "found libtorch at " ${TORCH_LIBRARIES})
endif ()




add_executable(w_stop_node)
target_link_libraries(
        wstop_node
        ${catkin_LIBRARIES}
        ${TORCH_LIBRARIES}
        glog
        thor
)

HI !!Have you solved this problem?

run_model.cpp:(.text+0xf2):undefined reference to ‘ros::init(int&, char**, std::string const&, unsigned int)’
collect2: error: ld returned 1 exit status
irosnet/CMakeFiles/run_model.dir/build.make:190: recipe for target '/home/yjhdhr/catkin_ws/devel/lib/irosnet/run_model' failed
make[2]: *** [/home/yjhdhr/catkin_ws/devel/lib/irosnet/run_model] Error 1
CMakeFiles/Makefile2:916: recipe for target 'irosnet/CMakeFiles/run_model.dir/all' failed
make[1]: *** [irosnet/CMakeFiles/run_model.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

I had exactly the same problem, and I was very anxious.And I sent you an email, I hope you can see it.

Hi ,Have you solved the problem? ,I met the same problem, looking forward to you help, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround module: build Build system issues needs reproduction Someone else needs to try reproducing the issue given the instructions. No action needed from user triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

10 participants