Linking failure when building from source

I’m building from source, and build completes only until linking libtorch related stuff (fails with undefined references).

how to solve it? It happens in both master and tagged version.

I followed instructions here https://github.com/pytorch/pytorch#from-source

Following Undefined symbol when import lltm cpp extension
I added -D_GLIBCXX_USE_CXX11_ABI=0 ti CFLAGS after the attempt without it failed.

The relevant error:

[3963/3988] Linking CXX executable bin/torch_shm_manager
FAILED: bin/torch_shm_manager
: && /usr/bin/c++  -D_GLIBCXX_USE_CXX11_ABI=0 -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -DNDEBUG -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QN
NPACK -DUSE_XNNPACK -DUSE_INTERNAL_THREADPOOL_IMPL -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type
-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wn
o-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-error=pedantic -Wno-error=redundant-decls -Wno-er
ror=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -W
error=format -Wno-stringop-overflow -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3 -DNDEBUG -DNDEBUG  -rdynamic -Wl,-rpath -Wl,/usr/local/lib
 -Wl,--enable-new-dtags -pthread    -rdynamic caffe2/torch/lib/libshm/CMakeFiles/torch_shm_manager.dir/manager.cpp.o  -o bin/torch_shm_manager -L/home_
local/saareliad/miniconda3/envs/py38/lib -Wl,-rpath,/home_local/saareliad/pytorch/build/lib:/home_local/saareliad/miniconda3/envs/py38/lib:/usr/local/c
uda-10.2/lib64:  lib/libshm.so  -lrt  lib/libtorch.so  -Wl,--no-as-needed,/home_local/saareliad/pytorch/build/lib/libtorch_cpu.so -Wl,--as-needed  lib/
libprotobuf.a  -lpthread  -lmkl_intel_lp64  -lmkl_gnu_thread  -lmkl_core  -fopenmp  -lpthread  -lm  -ldl  lib/libmkldnn.a  -Wl,--no-as-needed,/home_loc
al/saareliad/pytorch/build/lib/libtorch_cuda.so -Wl,--as-needed  lib/libc10_cuda.so  /usr/local/cuda-10.2/lib64/libnvToolsExt.so  /usr/local/cuda-10.2/
lib64/libcudart.so  /usr/local/cuda-10.2/lib64/libcufft.so  /usr/local/cuda-10.2/lib64/libcurand.so  -lcublas  /usr/local/cuda-10.2/lib64/libcudnn.so
lib/libc10.so && :
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THFloatTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THDoubleTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `_THError(char const*, int, char const*, ...)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THCharTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THLongStorage_free(c10::StorageImpl*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THDoubleTensor_stride(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THHalfTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `gloo::getCudaPCIBusID(int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THBoolTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THLongTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THByteTensor_data(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THBoolTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THDoubleTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `gloo::EnforceNotMet::EnforceNotMet(char const*, int, char const*, std
::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THHalfTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THIntTensor_stride(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THByteTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THIntTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THLongStorage_size(c10::StorageImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THBFloat16Tensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THByteTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THIntTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THBFloat16Tensor_stride(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `_THAssertionFailed(char const*, int, char const*, char const*, ...)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `_THArgCheck(char const*, int, int, int, char const*, ...)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THShortTensor_stride(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THLongTensor_stride(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THCharTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THFloatTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THByteTensor_isContiguous(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THFloatTensor_stride(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THShortTensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THBFloat16Tensor_nElement(c10::TensorImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THLongStorage_data(c10::StorageImpl const*)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THByteTensor_resize1d(c10::TensorImpl*, long)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THCharTensor_stride(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THLongTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THHalfTensor_stride(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THShortTensor_size(c10::TensorImpl const*, int)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THLongStorage_newWithSize(long)'
/home_local/saareliad/pytorch/build/lib/libtorch_cuda.so: undefined reference to `THByteTensor_stride(c10::TensorImpl const*, int)'
collect2: error: ld returned 1 exit status