Repository: pytorch
Issue: [Caffe2] compilation linker error `libtbb.so.2: undefined reference to std::__exception_ptr`
Labels: module: crash,module: build,caffe2

I am unable to compile caffe2 under fedora 27, cuda 9.1, cudnn 7. The linker fails with

//usr/lib64/libtbb.so.2: undefined reference to `std::__exception_ptr::exception_ptr::exception_ptr(void*)@CXXABI_1.3.11'
//usr/lib64/libtbb.so.2: undefined reference to `__cxa_init_primary_exception@CXXABI_1.3.11'

This happens when linking  `bin/common_subexpression_elimination_test`, `bin/conv_to_nnpack_transform_test`, `bin/generate_proposals_op_util_boxes_test` and some other tests as far as I can tell.

Full gcc linker command before the first error:

> /tools/miniconda2/bin/g++-5  -fvisibility-inlines-hidden -DONNX_NAMESPACE=onnx_c2 -O2 -fPIC -Wno-narrowing -Wno-invalid-partial-specialization -O3 -DNDEBUG  -rdynamic caffe2/CMakeFiles/common_subexpression_elimination_test.dir/transforms/common_subexpression_elimination_test.cc.o  -o bin/common_subexpression_elimination_test  -Wl,-rpath,/home/pytorch/build/lib:/data/libs/cuda-9.1/lib64:/home/cudnn/v7/lib64: lib/libgtest_main.a lib/libgloo_cuda.a -Wl,--no-as-needed -Wl,--as-needed lib/libcaffe2_gpu.so lib/libcaffe2.so lib/libprotobuf.a -lpthread /usr/lib64/libgflags.so /usr/lib64/libglog.so /usr/lib64/libcuda.so /data/libs/cuda-9.1/lib64/libcurand.so /home/cudnn/v7/lib64/libcudnn.so /data/libs/cuda-9.1/lib64/libnvrtc.so /data/libs/cuda-9.1/lib64/libcublas.so /data/libs/cuda-9.1/lib64/libcublas_device.a lib/libgtest.a -pthread ../third_party/nccl/build/lib/libnccl_static.a /data/libs/cuda-9.1/lib64/libcudart_static.a -ldl -lrt lib/libgloo.a /data/libs/cuda-9.1/lib64/libcudart.so -lcuda /data/libs/cuda-9.1/lib64/libnvrtc.so -lpthread -lrt

As referenced in [this issue](https://github.com/negativo17/cuda-gcc/issues/1), I suppose it has something to do with my system libraries compiled with gcc 7 instead of gcc 5 (which I use since cuda is not compatible with gcc 7), however I don't see what is dependent on `tbb` in caffe2 and how I can maintain my own local version of `tbb` compiled with gcc 5.

## System Info
- Caffe2
- Build command:
PATH=/data/libs/cuda-9.1/bin:$PATH cmake -DCUDNN_ROOT_DIR=/home/cudnn/v7 -DCUDA_HOST_COMPILER=/tools/miniconda2/bin/gcc-5 -DCMAKE_CXX_COMPILER=/tools/miniconda2/bin/g++-5 -DCMAKE_C_COMPILER=/tools/miniconda2/bin/gcc-5 -DCUDA_ARCH_NAME=Manual .. -DCMAKE_DISABLE_FIND_PACKAGE_Eigen3=TRUE -DCUDA_ARCH_BIN="35 50 52 60 61 70"
- OS: fedora 27

CMake summary:
> - General:
> --   CMake version         : 3.11.20180426-ge52cf
> --   CMake command         : /home/apps/cmake/bin/cmake
> --   Git version           : v0.1.11-8054-gf98b77808-dirty
> --   System                : Linux
> --   C++ compiler          : /tools/miniconda2/bin/g++-5
> --   C++ compiler version  : 5.3.0
> --   BLAS                  : Eigen
> --   CXX flags             :  -fvisibility-inlines-hidden -DONNX_NAMESPACE=onnx_c2 -O2 -fPIC -Wno-narrowing -Wno-invalid-partial-specialization
> --   Build type            : Release
> --   Compile definitions   : 
> -- 
> --   BUILD_BINARY          : ON
> --   BUILD_CUSTOM_PROTOBUF : ON
> --     Link local protobuf : ON
> --   BUILD_DOCS            : OFF
> --   BUILD_PYTHON          : ON
> --     Python version      : 2.7.14
> --     Python includes     : /usr/include/python2.7
> --   BUILD_SHARED_LIBS     : ON
> --   BUILD_TEST            : ON
> --   USE_ATEN              : OFF
> --   USE_ASAN              : OFF
> --   USE_CUDA              : ON
> --     CUDA static link    : OFF
> --     CUDA version        : 9.1
> --     CuDNN version       : 7.0.3
> --     CUDA root directory : /data/libs/cuda-9.1
> --     CUDA library        : /usr/lib64/libcuda.so
> --     cudart library      : /data/libs/cuda-9.1/lib64/libcudart_static.a;-pthread;dl;/usr/lib64/librt.so
> --     cublas library      : /data/libs/cuda-9.1/lib64/libcublas.so;/data/libs/cuda-9.1/lib64/libcublas_device.a
> --     curand library      : /data/libs/cuda-9.1/lib64/libcurand.so
> --     CuDNN library       : /home/cudnn/v7/lib64/libcudnn.so
> --     nvrtc               : /data/libs/cuda-9.1/lib64/libnvrtc.so
> --     CUDA include path   : /data/libs/cuda-9.1/include
> --     NVCC executable     : /data/libs/cuda-9.1/bin/nvcc
> --     CUDA host compiler  : /tools/miniconda2/bin/gcc-5
> --     USE_TENSORRT        : OFF
> --   USE_EIGEN_FOR_BLAS    : 1
> --   USE_FFMPEG            : OFF
> --   USE_GFLAGS            : ON
> --   USE_GLOG              : ON
> --   USE_GLOO              : ON
> --   USE_LEVELDB           : OFF
> --   USE_LITE_PROTO        : OFF
> --   USE_LMDB              : ON
> --     LMDB version        : 0.9.21
> --   USE_METAL             : OFF
> --   USE_MKL               : 
> --   USE_MOBILE_OPENGL     : OFF
> --   USE_MPI               : OFF
> --   USE_NCCL              : ON
> --   USE_NERVANA_GPU       : OFF
> --   USE_NNPACK            : ON
> --   USE_OBSERVERS         : ON
> --   USE_OPENCL            : OFF
> --   USE_OPENCV            : ON
> --     OpenCV version      : 3.2.0
> --   USE_OPENMP            : OFF
> --   USE_PROF              : OFF
> --   USE_REDIS             : OFF
> --   USE_ROCKSDB           : OFF
> --   USE_ZMQ               : OFF