我試圖從源代碼構建OpenCV。我有protobuf安裝到我的主目錄;它是用--enable-shared
建造的。 LD_LIBRARY_PATH
頭上有$HOME/lib
; LIBRARY_PATH
和LD_RUN_PATH
設置爲$LD_LIBRARY_PATH
,並且CPATH
設置爲$HOME/include
。 PKG_CONFIG_PATH
是$HOME/lib/pkgconfig
。OpenCV構建從源代碼構建的protobuf的未定義引用
下面是一些有關版本:
opencv==3.1.0
gcc==4.8.5
g++==4.8.5
python==3.5.2
protobuf==2.6.1
我的CMake命令
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=$HOME -D OPENCV_EXTRA_MODULES_PATH=$HOME/opencv_contrib-3.1.0/modules -D PYTHON_DEFAULT_EXECUTABLE=$HOME/bin/python -D CMAKE_PREFIX_PATH=$HOME ..
cmake的成功,甚至說,它發現的protobuf在<~>/lib/libprotobuf.so
。但是找不到它。
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::InitEmptyString()'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::empty_string_once_init_'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::empty_string_'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::io::CodedInputStream::BytesUntilTotalBytesLimit() const'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/opencv_test_dnn] Error 1
make[1]: *** [modules/dnn/CMakeFiles/opencv_test_dnn.dir/all] Error 2
其他一些地方提到protobuf的多個版本可能會導致問題。有是/lib64中的另一個protobuf,但由於我沒有root權限,我無法刪除它。所以我不確定解決方法是什麼。
我在GCC 4.8.5或4.9中遇到了同樣的問題,但openCV可以用gcc 5.4編譯。不幸的是,我需要使用早期的GCC來構建,因爲Matlab尚未正式支持GCC 5 – Blaze