Failed to use libtorch components with cmake

Asked by Chun Cai

I'm using libtorch-dev in my c++ project with cmake. All requirements are installed by apt under ubuntu 22.04 . However, it tried to find libc10.so in a wrong path.
Please reproduce as follow using docker:

- CMakeLists.txt:
cmake_minimum_required(VERSION 3.18)
find_package(Torch REQUIRED)
- dockerfile:
FROM ubuntu:latest
RUN apt-get update && apt-get install -y g++ libtorch-dev cmake
COPY . .
RUN cmake .
- run `docker build .`

The error message goes as follows:

-- Caffe2: Protobuf version 3.12.4
CMake Error at sr/lib/x86_64-linux-gnu/cmake/Caffe2/Caffe2Targets.cmake:116 (message):
  The imported target "c10" references the file

     "/usr/lib/lib/libc10.so.1.8.0"

  but this file does not exist. Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/usr/lib/x86_64-linux-gnu/cmake/Caffe2/Caffe2Targets.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  sr/lib/x86_64-linux-gnu/cmake/Caffe2/Caffe2Config.cmake:116 (include)
  sr/lib/x86_64-linux-gnu/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:2 (find_package)

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu pytorch Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

What is the output of:

sudo updatedb; locate libc10.so*

Thanks

Revision history for this message
Chun Cai (caic99) said :
#2

Hi andrew,
Are you locating the lib location? I've run `dpkg -L libtorch-dev | grep libc10.so`, and the result is `/usr/lib/x86_64-linux-gnu/libc10.so`.
And, `ls /usr/lib/x86_64-linux-gnu | grep libc10.so` produces
```
libc10.so
libc10.so.1.8
libc10.so.1.8.0
```
Hope this would help. I suspect the problem lies in the cmake config files of Caffe2 in Torch.
Thanks!

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

You could make a symlink to the file to satisfy the requirement

Revision history for this message
Manfred Hampl (m-hampl) said (last edit ):
#4

For diagnostic purposes, what is the output of the commands

uname -a
lsb_release -crid
dpkg -l | grep -i -e torch -e libprotobuf

The same problem has already been reported in Debian, https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=997931

Maybe the error is in the file /usr/lib/x86_64-linux-gnu/cmake/Caffe2/Caffe2Targets-relwithdebinfo.cmake

Try changing line 11
from
  IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib/libc10.so.1.8.0"
to
  IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/x86_64-linux-gnu/libc10.so.1.8.0"

Revision history for this message
Chun Cai (caic99) said :
#5

Hi @Manfred,
I ran the following commands in a new docker image based on ubuntu 22.04:

> uname -a
Linux 439408b9362e 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

> lsb_release -crid
Distributor ID: Ubuntu
Description: Ubuntu 22.04 LTS
Release: 22.04
Codename: jammy

> dpkg -l | grep -i -e torch -e libprotobuf
ii libprotobuf-dev:amd64 3.12.4-1ubuntu7 amd64 protocol buffers C++ library (development files) and proto files
ii libprotobuf-lite23:amd64 3.12.4-1ubuntu7 amd64 protocol buffers C++ library (lite version)
ii libprotobuf23:amd64 3.12.4-1ubuntu7 amd64 protocol buffers C++ library
ii libtorch-dev 1.8.1-4 amd64 Tensors and Dynamic neural networks in Python (Development Files)
ii libtorch1.8:amd64 1.8.1-4 amd64 Tensors and Dynamic neural networks in Python (Shared Objects)

I wonder who will actively maintain this package? I'll try submitting an issue on github.com/pytorch/pytorch.
Thank you all for your help! @andrew @manfred

Revision history for this message
Manfred Hampl (m-hampl) said :
#6

Have you tested whether the change in Caffe2Targets-relwithdebinfo.cmake helps (as a dirty workaround)?

Revision history for this message
Chun Cai (caic99) said :
#7

Hi @Manfred,
The solution you proposed works! However, patching it using symlink would be more convenient.
Thanks again!

Revision history for this message
Manfred Hampl (m-hampl) said :
#8

I am aware that the modification that I suggested is a dirty workaround, which would even require different modifications depending on computer architecture.
Unfortunately my knowledge of cmake is limited, and I do not know which original source file would need a change that then leads to the correction in Caffe2Targets-relwithdebinfo.cmake

Can you help with this problem?

Provide an answer of your own, or ask Chun Cai for more information if necessary.

To post a message you must log in.