you may refer to https://apaszke.github.io/torch-internals.html 96
# clone Torch repository
git clone https://github.com/torch/torch7
mkdir th_build
cd th_build
# configure TH build
cmake ../torch7/lib/TH
# compile library
make
# install shared library and header files
make install


Then, you only have to #include <TH/TH.h> in your program and link the library during the compilation process (-lTH).