2016-06-30 75 views
1

我試圖從源代碼構建OpenCV。我有protobuf安裝到我的主目錄;它是用--enable-shared建造的。 LD_LIBRARY_PATH頭上有$HOME/lib; LIBRARY_PATHLD_RUN_PATH設置爲$LD_LIBRARY_PATH,並且CPATH設置爲$HOME/includePKG_CONFIG_PATH$HOME/lib/pkgconfigOpenCV構建從源代碼構建的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權限,我無法刪除它。所以我不確定解決方法是什麼。

+0

我在GCC 4.8.5或4.9中遇到了同樣的問題,但openCV可以用gcc 5.4編譯。不幸的是,我需要使用早期的GCC來構建,因爲Matlab尚未正式支持GCC 5 – Blaze

回答

0

我最近遇到了同樣的問題,因爲我安裝了最新的protobuf(3.1.0)並使用GCC 4.9構建了我的opencv。當我切換回GCC 5時,OpenCV 3.1可以成功構建。

如果你想和OpenCV 3.1一起使用Matlab,我認爲你可能需要降級你的protobuf版本,比如protobuf-2.5.0,那麼你可以使用GCC 4.9來重建OpenCV。