Building libtorch C++ distribution from source

Hi,
In order to use the libtorch c++ frontend, I have installed the pre-built distribution as explained here:
https://pytorch.org/cppdocs/installing.html

It works flawlessly, but now I need to be able to build it from source using CMake in order to provide it as a dependency for another project.

Is there a documentation explaining how to do that? All docs that I have found for building from source use the setup.py approach and I am not sure that this produces an installable lib which can be consumed from CMake projects.

Thanks.

2 Likes

There is tools/build_libtorch.py. I could not get it to do what I want, but maybe you’ll figure it out (if you do please update with your solution! :slight_smile: ).

3 Likes

Thanks for the hint. Actually, looking at the provided scripts, I have found a procedure which works for me:

  1. git clone
  2. cd pytorch
  3. mkdir build
  4. cd build
  5. ccmake …/ (and the choose what applies: BUILD_TORCH BUILD_BINARY, BUILD_CAFFE2_OPS and the chosen install dir)
  6. make -j install

I have only tested that I can use find_package and build simple examples using the c++ API

4 Likes

Can you please clarify what you did? why ccmake and not cmake? why …/ and not … ?
if interested in the c++ libtorch (includes, libs and share stuff) what flags apply?

1 Like