Repository: pytorch/pytorch

Issue #60341: C++ version 1.9.0 libtorch dynamic load fails -- GCC only
Created: 2021-06-20T15:43:09Z
🐛 Bug
When building our shared library application with libtorch 1.9.0 (and the nightly build),
we are seeing an error from the GCC build (clang is fine)
.so: undefined symbol: _ZTIN5torch2nn6ModuleE

> echo _ZTIN5torch2nn6ModuleE|c++filt
typeinfo for torch::nn::Module

In GCC, the first non-inline virtual method is used to determine the the translation unit where the vtable and typeinfo objects are created -- was there some change to nn::Module's virtual functions that might cause this(?).
I'm seeing the problem on the CPU or CUDA 11.1 versions for Linux.
Thanks for looking into this.
cc @ezyang @gchanan @zou3519 @bdhirsh @jbschlosser @anjali411 @seemethere @malfet @walterddr @yf225 @glaringlee

Duplicate issue #61260: libtorch_cpu.so: undefined symbol: _ZN3c1010ThreadPool3runESt8functionIFvvEE
Created: 2021-07-05T15:51:20Z
It seem like the version of libtorch cause the error. But I test the different version of libtorch, and got the same error, how to solve it?
The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /usr/local/cuda (found version "10.0")
-- Caffe2: CUDA detected: 10.0
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 10.0
-- Found CUDNN: /usr/lib/x86_64-linux-gnu/libcudnn.so
-- Found cuDNN: v7.5.0 (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libcudnn.so)
-- Autodetected CUDA architecture(s): 7.5
-- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
-- Found Torch: /project/libtorch-cxx11-abi-shared-with-deps-1.7.1+cu101/libtorch/lib/libtorch.so
-- Configuring done
-- Generating done
-- Build files have been written to:/project/Ultra-Fast-Lane-Detection/cpp/build
Scanning dependencies of target carimage_local
[ 50%] Building CXX object CMakeFiles/carimage_local.dir/src/maintest.cpp.o
[100%] Linking CXX executable carimage_local
[100%] Built target detect_project
./ detect_project: symbol lookup error: /project/libtorch-cxx11-abi-shared-with-deps-1.7.1+cu101/libtorch/lib/libtorch_cpu.so: undefined symbol: _ZN3c1010ThreadPool3runESt8functionIFvvEE

Closing comment (2021-07-06T21:33:45Z): Seems related to #60341
Never compiler should solve the issue, or explicitly link your project against libtorch_cpu (and libtorch_cuda)