C++ Opencv链接库-未定义的引用

C++ Opencv链接库-未定义的引用,c++,opencv,linker,undefined-reference,C++,Opencv,Linker,Undefined Reference,我试图在raspberry pi 3上编译opencv代码。但是,它总是给出“未定义引用…”错误,我认为链接有问题 编译: g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp -L/opt/lib/ -L/opt/Deneme/opencv/a/ -opencv_calib3d -opencv_core -opencv_features2d -opencv_flann -opencv_highgui -opencv_imgco

我试图在raspberry pi 3上编译opencv代码。但是,它总是给出“未定义引用…”错误,我认为链接有问题

编译:

g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp
-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
-I/opt/Deneme/Include/opencv -I/opt/Deneme/Include/
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&)'
pkg config opencv--libs:

g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp
-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
-I/opt/Deneme/Include/opencv -I/opt/Deneme/Include/
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&)'
pkg config opencv--cflags:

g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp
-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
-I/opt/Deneme/Include/opencv -I/opt/Deneme/Include/
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&)'
opencv.pc文件:

g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp
-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
-I/opt/Deneme/Include/opencv -I/opt/Deneme/Include/
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&)'
错误:

g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp
-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
-I/opt/Deneme/Include/opencv -I/opt/Deneme/Include/
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&)'
Face_Detection.cpp:(.text+0x94):未定义对“cv::imread(std::string const&,int)”的引用
Face_Detection.cpp:(.text+0xd8):未定义对“cv::_InputArray::_InputArray(cv::Mat const&)”的引用
Face_Detection.cpp:(.text+0xec):未定义对“cv::_OutputArray::_OutputArray(cv::Mat&)”的引用
Face_Detection.cpp:(.text+0x128):对“cv::resize(cv::_InputArray常量和,cv:_OutputArray常量和,cv::Size,double,double,int)”的未定义引用
Face_Detection.cpp:(.text+0x1e8):对“cv::_InputArray::_InputArray(cv::Mat const&)”的未定义引用
Face_Detection.cpp:(.text+0x218):未定义对“cv::_InputArray::_InputArray(cv::Mat const&)”的引用
Face_Detection.cpp:(.text+0x250):对“cv::_OutputArray::_OutputArray(cv::Mat&)”的未定义引用
Face_Detection.cpp:(.text+0x26c):未定义对“cv::hconcat(cv::_inputarrayconst&,cv:_inputarrayconst&,cv:_outputarrayconst&)”的引用
Face_Detection.cpp:(.text+0x298):未定义对“cv::_InputArray::_InputArray(cv::Mat const&)”的引用
Face_Detection.cpp:(.text+0x2c8):未定义对“cv::_InputArray::_InputArray(cv::Mat const&)”的引用

提前感谢。

这是链接器订单错误。尝试改变

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


您可以找出哪个lib具有imread/resize/hconcat,并在调用g++时手动添加它,以检查问题是在查找lib中还是在使用pkg config时。另外,你确定opencv\u flann处理正确吗?我按照你说的做了,但仍然会出现同样的错误。你是从源代码构建opencv的吗?您是否运行了
sudo ldconfig-v
?是的,我运行了ldconfig-v。输出不包含任何这些库,但我运行export LD_LIBRARY_PATH=/opt/lib/i不确定,但尝试在
/etc/LD.so.conf.d/
中创建一个costment
opencv.conf
config。此文件仅包含opencv库路径,
/opt/lib/
/opt/Deneme/opencv/a/
。运行
ldconf
并尝试重新启动pi。或者简单地将
/opt/lib
中的所有lib链接到
/usr/local/lib
,并制作一些服装到
opencv.pc