2016-12-30 138 views
0

我試圖編譯樹莓pi 3上的opencv代碼。但是,它始終提供「未定義的引用...」錯誤,我認爲有鏈接問題。Opencv鏈接庫 - 未定義的參考

編譯:

g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp 

pkg配置的OpenCV --libs:

-L/opt/lib/ -L/opt/Deneme/opencv/a/ -opencv_calib3d -opencv_core 
-opencv_features2d -opencv_flann -opencv_highgui -opencv_imgcodecs 
-opencv_imgproc -opencv_ml -opencv_objdetect -opencv_photo -opencv_shape 
-opencv_stitching -opencv_superres -opencv_videoio -opencv_video 
-opencv_calib3d_pch_dephelp -opencv_contrib_pch_dephelp 
-opencv_core_pch_dephelp -opencv_features2d_pch_dephelp 
-opencv_flann_pch_dephelp -opencv_gpu_pch_dephelp 
-opencv_haartraining_engine -opencv_highgui_pch_dephelp 
-opencv_imgproc_pch_dephelp -opencv_legacy_pch_dephelp 
-opencv_ml_pch_dephelp -opencv_objdetect_pch_dephelp 
-opencv_video_pch_dephelp 

pkg配置的OpenCV --cflags:

-I/opt/Deneme/Include/opencv -I/opt/Deneme/Include/ 

opencv.pc文件:

includedir=/opt/Deneme/Include/opencv 
dir2=/opt/Deneme/Include/ 
libdir=/opt/lib/ 
libdir2=/opt/Deneme/opencv/a/ 

Name: opencv 
Description: The opencv library 
Version: 3.x.x 
Cflags: -I${includedir} -I${dir2} 
Libs: -L${libdir} -opencv_calib3d -opencv_core -opencv_features2d -   opencv_flann -opencv_highgui -opencv_imgcodecs -opencv_imgproc -opencv_ml -opencv_objdetect -opencv_photo -opencv_shape -opencv_stitching -opencv_superres -opencv_videoio -opencv_video -L${libdir2} -opencv_calib3d_pch_dephelp -opencv_contrib_pch_dephelp -opencv_core_pch_dephelp -opencv_features2d_pch_dephelp -opencv_flann_pch_dephelp -opencv_gpu_pch_dephelp -opencv_haartraining_engine -opencv_highgui_pch_dephelp -opencv_imgproc_pch_dephelp -opencv_legacy_pch_dephelp -opencv_ml_pch_dephelp -opencv_objdetect_pch_dephelp -opencv_video_pch_dephelp 

錯誤:

Face_Detection.cpp:(.text+0x94): undefined reference to `cv::imread(std::string const&, int)' 

Face_Detection.cpp:(.text+0xd8): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 

Face_Detection.cpp:(.text+0xec): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 

Face_Detection.cpp:(.text+0x128): undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)' 

Face_Detection.cpp:(.text+0x1e8): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 

Face_Detection.cpp:(.text+0x218): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 

Face_Detection.cpp:(.text+0x250): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 

Face_Detection.cpp:(.text+0x26c): undefined reference to `cv::hconcat(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&)' 

Face_Detection.cpp:(.text+0x298): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 

Face_Detection.cpp:(.text+0x2c8): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 

在此先感謝。

+0

你可以找出哪些解放運動在imread /調整/ hconcat並添加手動調用時,G ++,只是爲了檢查問題是否在尋找lib或與pkg配置。你也確定' - opencv_flann'處理正確嗎? – stijn

+0

我做了你所說的,但它仍然給出同樣的錯誤。 – HelloWorld

回答

0

這是鏈接器順序錯誤。嘗試改變

g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp 

g++ Face_Detection.cpp `pkg-config --libs --cflags opencv` 
+0

不過,它給出同樣的錯誤。 – HelloWorld

+0

您是從源代碼構建opencv嗎?你運行過'sudo ldconfig -v'嗎? –

+0

是的,我運行ldconfig -v。輸出不包含任何這些lib,但我運行export LD_LIBRARY_PATH =/opt/lib/ – HelloWorld