本文記錄如何在 Ubuntu 16.04 (14.04) 上搭建 Cuda, Matlab 與 OpenCV 的開發環境。
Troubleshooting
先把 troubleshooting 放前面是因為本來就是為了解決第一個 error 才有了這一篇紀錄XD。
Error 1 與 error 2 都是發生在 Matlab R2015b 已經安裝好的情況下才產生。更準確來說是程式讀取到 Matlab 自帶的 libtiff.h 才產生的 error。
Error 1
某人開發的程式,在 Matlab 安裝完畢後,編譯時 include Matlab library 與 header 然後出現錯誤:
如果編譯時不引用到 Matlab 的東西,就不會有事情。但是這道程式就是必須要同時使用 Matlab 與 OpenCV。
根據 google 來的資料,應該是 OpenCV 編譯時沒有啟用 TIFF (?)。
所以解決方法就是重新編譯 OpenCV 並且啟用 TIFF。
Error 2
重新編譯 OpenCV 時,出現錯誤:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadDirectory@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFWriteEncodedStrip@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFIsTiled@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFOpen@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadEncodedStrip@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFSetField@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFWriteScanline@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFGetField@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFScanlineSize@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFNumberOfStrips@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFSetWarningHandler@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFSetErrorHandler@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadEncodedTile@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFReadRGBATile@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFClose@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFRGBAImageOK@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0' collect2: error: ld returned 1 exit status tools/CMakeFiles/compute_image_mean.dir/build.make:134: recipe for target 'tools/compute_image_mean' failed make[2]: *** [tools/compute_image_mean] Error 1 CMakeFiles/Makefile2:473: recipe for target 'tools/CMakeFiles/compute_image_mean.dir/all' failed make[1]: *** [tools/CMakeFiles/compute_image_mean.dir/all] Error 2 Makefile:127: recipe for target 'all' failed make: *** [all] Error 2
|
同樣根據 error 1 的參考資料:https://github.com/BVLC/caffe/issues/4436。
在 CMakeCache.txt
裡面發現:WITH_TIFF=ON
, BUILD_TIFF=OFF
。
看起來原本 cmake
就有偵測到系統的 libtiff,因此預設不編譯 tiff。
既然這樣,所以解決方法就是在 cmake
時,增加參數 -D BUILD_TIFF=ON
。
Error 3
OpenCV 已經編譯完成,但原本的程式重新編譯時出現:
1
| /usr/bin/ld: cannot find -lippicv
|
根據查到的資料,解決方法就是在編譯 OpenCV 時,cmake
階段增加 -D WITH_IPP=ON
。
System environment
兩套環境:
- Ubuntu 16.04 with Nvidia GeForce GTX 970
- Ubuntu 14.04 with Nvidia GeForce GT 620 OEM
第一套環境是從 OS 開始安裝;
第二套是一個已經存在的環境,只是再重新編譯 OpenCV (為了解決 TIFF 問題)。
其他的系統資訊:
- OpenCV: 3.2
- CUDA: 8.0
- Matlab: R2015b (or Octave 4.2)
- Nvidia driver: 375
- Java:
- Oracla Java 8 (on site 1)
- Oracle Java 7 (on site 2)
Continue reading