I tried to compile a static linked LibTorch on Ubuntu 18.04.
git clone -b v1.8.1 --recurse-submodule https://github.com/pytorch/pytorch.git && \
mkdir build_libtorch_static && cd build_libtorch_static && \
cmake -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE:STRING=Release -DUSE_CUDA:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=~/local/libtorch ../pytorch -DCMAKE_CXX_FLAGS:STRING=-fPIC && \
cmake --build . --target install --parallel
I ran into the following errors:
[100%] Linking CXX shared module python/caffe2_pybind11_state.cpython-39-x86_64-linux-gnu.so
[100%] Built target torch_shm_manager
[100%] Built target caffe2_pybind11_state
[100%] Linking CXX shared library ../../lib/libtorch_python.so
/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/libtorch_python.so' 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,
Jingzhao