![](/img/trans.png)
[英]GLEW and glfw compile error: undefined reference to symbol 'XConvertSelection'
[英]Raspberry Camera compile error: undefined reference to symbol
我正在嘗試為樹莓派編譯一個程序。 但是當我在 Geany 中運行構建時,我得到了這個錯誤:
g++ $(pkg-config opencv4 --cflags --libs) -o g++ $(pkg-config raspicam --cflags --libs) -o camera_2 camera_2.cpp (in directory: /home/pi/Desktop)
/usr/bin/ld: /tmp/ccTDUfOT.o: undefined reference to symbol '_ZN2cv6imshowERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayE'
/usr/bin/ld: //usr/local/lib/libopencv_highgui.so.405: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Compilation failed.
camera.cpp 文件如下所示:
#include <opencv2/opencv.hpp>
#include <raspicam_cv.h>
#include <iostream>
using namespace std;
using namespace cv;
using namespace raspicam;
Mat frame;
void Setup ( int argc,char **argv, RaspiCam_Cv &Camera )
{
Camera.set ( CAP_PROP_FRAME_WIDTH, ( "-w",argc,argv,400 ) );
Camera.set ( CAP_PROP_FRAME_HEIGHT, ( "-h",argc,argv,240 ) );
Camera.set ( CAP_PROP_BRIGHTNESS, ( "-br",argc,argv,50 ) );
Camera.set ( CAP_PROP_CONTRAST ,( "-co",argc,argv,50 ) );
Camera.set ( CAP_PROP_SATURATION, ( "-sa",argc,argv,50 ) );
Camera.set ( CAP_PROP_GAIN, ( "-g",argc,argv ,50 ) );
Camera.set ( CAP_PROP_FPS, ( "-fps",argc,argv,100));
}
int main(int argc,char **argv)
{
RaspiCam_Cv Camera;
Setup(argc, argv, Camera);
cout<<"Connecting to camera"<<endl;
if (!Camera.open())
{
cout<<"Failed to Connect"<<endl;
return -1;
}
cout<<"Camera Id = "<<Camera.getId()<<endl;
Camera.grab();
Camera.retrieve(frame);
imshow("frame", frame);
waitKey();
return 0;
}
到目前為止,我已經知道當我移除Mat frame;
錯誤沒有出現。
pkg-config 文件如下所示:
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv4/opencv2
includedir_new=${prefix}/include/opencv4
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.5.5
L: -Libs${exec_prefix}/lib -lopencv_calib3d -lopencv_core -lopencv_dnn -lopencv_features2d -lopencv_flann -lopencv_gapi -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_video -lopencv_videoio
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir_old} -I${includedir_new}
Geany 中的命令如下所示:
g++ $(pkg-config opencv4 --cflags --libs) -o g++ $(pkg-config raspicam --cflags --libs) -o %e %f
你知道什么是錯的,我需要改變什么嗎? 謝謝
參數-o g++
非常奇怪,因為它會生成一個名為g++
的 output 文件,這令人困惑,因為這也是編譯器的名稱。 您可能想要刪除它,因為您已經有了-o
參數。
其次,在鏈接程序時,鏈接在一起的不同對象/庫的順序通常很重要。 嘗試在命令末尾調用pkg-config
。
我已經解決了這個錯誤。 我在命令中添加了兩個庫:
g++ $(pkg-config opencv4 --cflags --libs) $(pkg-config raspicam --cflags --libs) -o %e %f -lopencv_highgui -lopencv_core
我想知道為什么這些庫在配置文件中不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.