Building Torch from Source

- 2 mins

Building Torch from Source

Recently I’ve needed to use the C++ interface of Torch, and am actually surprised to see how little information is out there about everything related to it. Everything I’ve found is pretty much what I’ve found through forums and questions bit by bit. Even for building it from the source doesn’t have a documentation. The README in the github page explains the usage of a setup script, but I ended up not being able to run it. Then you just have to somehow figure out another way to build it.

Although so far it looks trivial to build it with prior knowledge on git and CMake, it would save me some time if there were some documentation explaining step by step. This page is for my own future reference, but you’re welcome to correct me if you see something that can be improved.

So, here goes. First, let’s get the source from the GitHub:

git clone

This only brings the source for Torch. You need to pull the submodules it uses. But first, go into the directory of Torch.

cd pytorch
git submodule sync
git submodule update --init --recursive

Now, let’s create a directory for the build artifacts, and build from there.

mkdir build
cd build
cmake ..
make -j12
sudo make install

After these steps, you should have the library ready. After this point, if you want to further personalize the build settings, I suggest you use ccmake to see the options that you can adjust, and build with those settings.


Goksu Guvendiren

Goksu Guvendiren

Hi There!

rss facebook twitter github youtube mail spotify instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora