-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Description
🐛 Bug
When I compile a simple package (a for instance) using cmake, the exported
torch;torch_library;/usr/lib/libc10.so;/opt/cuda/lib/stubs/libcuda.so;/opt/cuda/lib/libnvrtc.so;/opt/cuda/lib/libnvToolsExt.so;/opt/cuda/lib64/libcudart.so;/usr/lib/libc10_cuda.so
Package a compiles successfully even if the linker fails to link torch_library.
The actual problem arises when I have another package (b), dependent on the already created package a. When I build, it fails with error
CMake Error at /home/vsury/dev/ros/pytorch-example/devel_isolated/a/share/a/cmake/aConfig.cmake:150 (message):
Project 'b' tried to find library '-Wl,--no-as-needed,$<TARGET_FILE:torch>
-Wl,--as-needed'. The library is neither a target nor built/installed
properly. Did you compile project 'a'? Did you find_package() it before
the subdirectory containing its code is included?
The reason has to do with torch_library because there is no library such as libtorch_library.so.
Looking further, it seems like that ${TORCH_LIBRARIES} is linked to ${Caffe2_MAIN_LIBS},
https://github.com/pytorch/pytorch/blob/master/cmake/TorchConfig.cmake.in#L41
and ${Caffe2_MAIN_LIBS} is linked to torch_library,
https://github.com/pytorch/pytorch/blob/master/cmake/Caffe2Config.cmake.in#L121
I do not understand the need for torch_library and removing it from
To Reproduce
Steps to reproduce the behavior:
- Create a package a with any script with torch functionalities (basically CMakeLists should contain find_package(Torch REQUIRED) and build target with torch libraries.
- Create another package b and make it depend on a.
- Compile package b to get the error.
Expected behavior
Successful build
Environment
Please copy and paste the output from our
- PyTorch Version (e.g., 1.0): 1.5.0
- OS (e.g., Linux): Archlinux
- How you installed PyTorch (
conda,pip, source): pacman -S - Build command you used (if compiling from source): cmake and make
- Python version:
- CUDA/cuDNN version:
- GPU models and configuration:
- Any other relevant information: