Errors when building static linked LibTorch

I tried to compile a static linked LibTorch on Ubuntu 18.04.

git clone -b v1.8.1 --recurse-submodule && \
mkdir build_libtorch_static && cd build_libtorch_static && \
cmake --build . --target install --parallel

I ran into the following errors:

[100%] Linking CXX shared module python/
[100%] Built target torch_shm_manager
[100%] Built target caffe2_pybind11_state
[100%] Linking CXX shared library ../../lib/
/usr/bin/ld: ../../lib/libtensorpipe_uv.a(process.c.o): relocation R_X86_64_PC32 against symbol `environ@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
caffe2/torch/CMakeFiles/torch_python.dir/build.make:1721: recipe for target 'lib/' failed

I tried PyTorch 1.8.1 and 1.8.0. No luck with both versions. The compilation works just fine if I set -DBUILD_SHARED_LIBS:BOOL=ON.

Any help would be highly appreciated.

Best regards,

I figured out the solution myself. I set -DBUILD_PYTHON:BOOL=OFF and that allows me to build the static libtorch library successfully. This is a bit tricky IMO.