Repository: pytorch
Issue: undefined symbols when using  libtorch and ITK
Labels: module: build,triaged

I build pytorch and libtorch from source(ubuntu18.04, anaconda, pytorch1.2.0, cuda9.2,ITK5.0,gcc7.5).
```
-- Caffe2: CUDA detected: 9.2
-- Caffe2: CUDA nvcc is: /usr/local/cuda-9.2/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda-9.2
-- Caffe2: Header version is: 9.2
-- Found cuDNN: v7.6.3  (include: /usr/local/cuda-9.2/include, library: /usr/local/cuda-9.2/lib64/libcudnn.so)
-- Autodetected CUDA architecture(s):  7.5 7.5
-- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
-- Configuring done
-- Generating done
-- Build files have been written to: /home/luqian/work/lib_test/model/bin
```
when using ITK and libtorch sperately, the cmake project can be great .But when linking libtorch and ITK together, I got lot of errors of "undefined symbols".
The ITK and Iibtorch are both installed from source.
```
[ 50%] Building CXX object CMakeFiles/ImageReadWrite.dir/predict.cpp.o
[100%] Linking CXX executable ImageReadWrite
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::MemoryAllocationError::MemoryAllocationError(std::string const&, unsigned int, std::string const&, std::string const&)’中：
predict.cpp:(.text._ZN3itk21MemoryAllocationErrorC2ERKSsjS2_S2_[_ZN3itk21MemoryAllocationErrorC5ERKSsjS2_S2_]+0x35)：对‘itk::ExceptionObject::ExceptionObject(std::string const&, unsigned int, std::string const&, std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::ImageFileReader<itk::Image<float, 3u>, itk::DefaultConvertPixelTraits<float> >::SetFileName(std::string const&)’中：
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE11SetFileNameERKSs[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE11SetFileNameERKSs]+0x52)：对‘itk::ProcessObject::GetInput(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::ImageFileReader<itk::Image<float, 3u>, itk::DefaultConvertPixelTraits<float> >::SetFileNameInput(itk::SimpleDataObjectDecorator<std::string> const*)’中：
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE16SetFileNameInputEPKNS_25SimpleDataObjectDecoratorISsEE[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE16SetFileNameInputEPKNS_25SimpleDataObjectDecoratorISsEE]+0x52)：对‘itk::ProcessObject::GetInput(std::string const&)’未定义的引用
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE16SetFileNameInputEPKNS_25SimpleDataObjectDecoratorISsEE[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE16SetFileNameInputEPKNS_25SimpleDataObjectDecoratorISsEE]+0xbb)：对‘itk::ProcessObject::SetInput(std::string const&, itk::DataObject*)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE[_ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE]+0x178)：对‘itk::ProcessObject::SetInput(std::string const&, itk::DataObject*)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE[_ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE]+0x1b0)：对‘itk::ProcessObject::RemoveInput(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE[_ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE]+0x1c0)：对‘itk::ProcessObject::SetPrimaryInputName(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE[_ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE]+0x1e8)：对‘itk::ProcessObject::SetPrimaryOutputName(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE[_ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE]+0x1f8)：对‘itk::ProcessObject::SetOutput(std::string const&, itk::DataObject*)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE[_ZTVN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEE]+0x200)：对‘itk::ProcessObject::RemoveOutput(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE[_ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE]+0x178)：对‘itk::ProcessObject::SetInput(std::string const&, itk::DataObject*)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE[_ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE]+0x1b0)：对‘itk::ProcessObject::RemoveInput(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE[_ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE]+0x1c0)：对‘itk::ProcessObject::SetPrimaryInputName(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE[_ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE]+0x1e8)：对‘itk::ProcessObject::SetPrimaryOutputName(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE[_ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE]+0x1f8)：对‘itk::ProcessObject::SetOutput(std::string const&, itk::DataObject*)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:(.data.rel.ro._ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE[_ZTVN3itk11ImageSourceINS_5ImageIfLj3EEEEE]+0x200)：对‘itk::ProcessObject::RemoveOutput(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::ImageFileReader<itk::Image<float, 3u>, itk::DefaultConvertPixelTraits<float> >::GenerateOutputInformation()’中：
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE25GenerateOutputInformationEv[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE25GenerateOutputInformationEv]+0x251)：对‘itk::ObjectFactoryBase::CreateAllInstance(char const*)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::ImageSource<itk::Image<float, 3u> >::GraftOutput(std::string const&, itk::DataObject*)’中：
predict.cpp:(.text._ZN3itk11ImageSourceINS_5ImageIfLj3EEEE11GraftOutputERKSsPNS_10DataObjectE[_ZN3itk11ImageSourceINS_5ImageIfLj3EEEE11GraftOutputERKSsPNS_10DataObjectE]+0x181)：对‘itk::ProcessObject::GetOutput(std::string const&)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::ImageSource<itk::Image<float, 3u> >::GraftNthOutput(unsigned int, itk::DataObject*)’中：
predict.cpp:(.text._ZN3itk11ImageSourceINS_5ImageIfLj3EEEE14GraftNthOutputEjPNS_10DataObjectE[_ZN3itk11ImageSourceINS_5ImageIfLj3EEEE14GraftNthOutputEjPNS_10DataObjectE]+0x1fc)：对‘itk::ProcessObject::MakeNameFromOutputIndex(unsigned long) const’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::ImageFileReader<itk::Image<float, 3u>, itk::DefaultConvertPixelTraits<float> >::GetFileNameInput() const’中：
predict.cpp:(.text._ZNK3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE16GetFileNameInputEv[_ZNK3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE16GetFileNameInputEv]+0x4e)：对‘itk::ProcessObject::GetInput(std::string const&) const’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::ImageFileReader<itk::Image<float, 3u>, itk::DefaultConvertPixelTraits<float> >::GetFileName() const’中：
predict.cpp:(.text._ZNK3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE11GetFileNameEv[_ZNK3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE11GetFileNameEv]+0x63)：对‘itk::ProcessObject::GetInput(std::string const&) const’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o：在函数‘itk::ImageFileReader<itk::Image<float, 3u>, itk::DefaultConvertPixelTraits<float> >::DoConvertBuffer(void*, unsigned long)’中：
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm]+0xb73)：对‘itk::ImageIOBase::GetComponentTypeAsString(itk::ImageIOBase::IOComponentType)’未定义的引用
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm]+0xbf9)：对‘itk::ImageIOBase::GetComponentTypeAsString(itk::ImageIOBase::IOComponentType)’未定义的引用
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm]+0xc5b)：对‘itk::ImageIOBase::GetComponentTypeAsString(itk::ImageIOBase::IOComponentType)’未定义的引用
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm]+0xcbd)：对‘itk::ImageIOBase::GetComponentTypeAsString(itk::ImageIOBase::IOComponentType)’未定义的引用
predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm]+0xd1f)：对‘itk::ImageIOBase::GetComponentTypeAsString(itk::ImageIOBase::IOComponentType)’未定义的引用
CMakeFiles/ImageReadWrite.dir/predict.cpp.o:predict.cpp:(.text._ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm[_ZN3itk15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEE15DoConvertBufferEPvm]+0xd81): 跟着更多未定义的参考到 itk::ImageIOBase::GetComponentTypeAsString(itk::ImageIOBase::IOComponentType)
collect2: error: ld returned 1 exit status
CMakeFiles/ImageReadWrite.dir/build.make:262: recipe for target 'ImageReadWrite' failed
make[2]: *** [ImageReadWrite] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/ImageReadWrite.dir/all' failed
make[1]: *** [CMakeFiles/ImageReadWrite.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
```