Repository: pytorch
Issue: Linker errors when building project with OpenCV
Labels: module: build,triaged

## 🐛 Bug

I'm trying to add libtorch to a working project. CMake configure throws no errors but when I try to build the project, it throws a lot of linking errors with OpenCV.
Then I tried to run the example code in [Installing C++ Distrbutions of Pytorch](https://pytorch.org/cppdocs/installing.html) and then it throws a different set of errors.
## To Reproduce

Steps to reproduce the behavior:

Code to reproduce the linking errors:
```
#include "opencv2/opencv.hpp"
#include "boost/filesystem.hpp"

int main(int argc, char** argv) {

    std::vector<cv::String> images;
    cv::glob("/home/madrogue/images/*.png",images);
    for (auto& image:images){
        cv::Mat temp = cv::imread(image,cv::IMREAD_GRAYSCALE);
        cv::pyrDown(temp, temp);
        boost::filesystem::path p(image);
        cv::imwrite("/home/madrogue/reduced/" + p.filename().string(),temp);
    }

    return 0;
}

```
Code to reproduce the general errors:
```
#include <torch/torch.h>
#include <iostream>

int main() {
  torch::Tensor tensor = torch::rand({2, 3});
  std::cout << tensor << std::endl;
}
```

## Expected behavior

Libtorch should be added without linking errors with OpenCV.

## Environment

 - PyTorch Version (e.g., 1.0): 1.1
 - OS (e.g., Linux): Ubuntu 18.04
 - How you installed PyTorch (`conda`, `pip`, source): libtorch
 - Python version: 3.6.7
 - CUDA/cuDNN version: 10.0
 - GPU models and configuration: Nvidia GeForce GTX 960 
 - Any other relevant information: CLion 2019.1.4 OpenCV 4.1

## Additional context

Linking errors with OpenCV

```
====================[ Build | dcv_Runner | Release ]========================
/home/madrogue/dep/clion-2019.1/bin/cmake/linux/bin/cmake --build /home/madrogue/computer-vision/otro_anpr/anpr/cmake-build-release --target dcv_Runner -- -j 4
Scanning dependencies of target dcv_Runner
[  0%] Building CXX object runner/CMakeFiles/dcv_Runner.dir/Runner.cpp.o
[100%] Linking CXX executable dcv_Runner
CMakeFiles/dcv_Runner.dir/Runner.cpp.o: In function `main':
Runner.cpp:(.text.startup+0xb9): undefined reference to `cv::glob(std::string, std::vector<std::string, std::allocator<std::string> >&, bool)'
Runner.cpp:(.text.startup+0x111): undefined reference to `cv::imread(std::string const&, int)'
Runner.cpp:(.text.startup+0x276): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status
runner/CMakeFiles/dcv_Runner.dir/build.make:99: recipe for target 'runner/dcv_Runner' failed
make[3]: *** [runner/dcv_Runner] Error 1
CMakeFiles/Makefile2:472: recipe for target 'runner/CMakeFiles/dcv_Runner.dir/all' failed
make[2]: *** [runner/CMakeFiles/dcv_Runner.dir/all] Error 2
CMakeFiles/Makefile2:484: recipe for target 'runner/CMakeFiles/dcv_Runner.dir/rule' failed
make[1]: *** [runner/CMakeFiles/dcv_Runner.dir/rule] Error 2
Makefile:196: recipe for target 'dcv_Runner' failed
make: *** [dcv_Runner] Error 2

```

Error when running the installing example found in [Installing C++ Distrbutions of Pytorch](https://pytorch.org/cppdocs/installing.html):

```
====================[ Build | dcv_Runner | Release ]========================
/home/madrogue/dep/clion-2019.1/bin/cmake/linux/bin/cmake --build /home/madrogue/computer-vision/otro_anpr/anpr/cmake-build-release --target dcv_Runner -- -j 4
Scanning dependencies of target dcv_Runner
[  0%] Building CXX object runner/CMakeFiles/dcv_Runner.dir/Runner.cpp.o
[100%] Linking CXX executable dcv_Runner
/usr/bin/ld: CMakeFiles/dcv_Runner.dir/Runner.cpp.o: undefined reference to symbol '_ZN3c106Symbol14fromQualStringERKSs'
//home/madrogue/dep/libtorch/lib/libcaffe2.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
runner/CMakeFiles/dcv_Runner.dir/build.make:84: recipe for target 'runner/dcv_Runner' failed
make[3]: *** [runner/dcv_Runner] Error 1
CMakeFiles/Makefile2:472: recipe for target 'runner/CMakeFiles/dcv_Runner.dir/all' failed
make[2]: *** [runner/CMakeFiles/dcv_Runner.dir/all] Error 2
CMakeFiles/Makefile2:484: recipe for target 'runner/CMakeFiles/dcv_Runner.dir/rule' failed
make[1]: *** [runner/CMakeFiles/dcv_Runner.dir/rule] Error 2
Makefile:196: recipe for target 'dcv_Runner' failed
make: *** [dcv_Runner] Error 2
```