0

i am currently trying to use Pytorch in my C++ program by including & linking libtorch into the project. Build system is meson where i have the following top-level meson.build file torch_dep = dependency('torch')

which then is used in my sub-level meson.build:

main = executable(
      name,
      [
        'PytorchModel.cpp',
      ],
      include_directories : [
        project_incdir,
      ]
      install : true,
      dependencies : [
        torch_dep,
    ]

When building i get the error:

meson.build:12:0: ERROR: Dependency "torch" not found, tried pkgconfig and cmake

I also checked pkg-config list and libtorch is not in there. How can i make this link? Another thing i tried is to download/unzip libtorch manually and move it to /usr/include/. Still it is not recognized. Also tried build_rpath : "/usr/include/libtorch" in the executable to use the manual path. Still not working.

My goal in the end is to use #include <torch/script.h> in my .cpp file.

I am very unexperienced with meson, so any help is appreciated.

s0H57
  • 3
  • 1
  • See [this](https://stackoverflow.com/a/62132772/8925535) – droptop Aug 22 '21 at 22:46
  • Thanks @droptop. That seems to work for finding the library, but somehow it does not include the libtorch inside the build so i still get fatal error: torch/script.h: No such file or directory. Any clue how to link my file with the library? – s0H57 Aug 23 '21 at 07:55
  • You'll have to add `script.h`'s directory to the `include_directories` list – droptop Aug 23 '21 at 22:45
  • Do you have the devel package installed? And if you do, have you tried `dependency('Torch')`. It looks like Torch only has cmake files, and those can be case sensitive. – dcbaker Aug 24 '21 at 04:45

0 Answers0