【发布时间】:2022-01-23 01:48:27
【问题描述】:
我正在尝试为树莓派编译一个程序。 但是当我在 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
你知道什么是错的,我需要改变什么吗? 谢谢
【问题讨论】:
-
嗯?你不能运行
g++ ... -o g++ ...,因为你会覆盖你的编译器,或者在你当前的目录中做一些看起来像编译器的东西。只要有一个-o XXXXXXX是你编译程序的名称。 -
感谢您的回答。我总共有两个构建命令:``` g++ $(pkg-config opencv4 --cflags --libs) -o %e %f g++ $(pkg-config raspicam --cflags --libs) -o %e %f ``` 我应该单独运行它们还是可以合并它们?我在 rasbian Geany IDE 的“设置构建命令”中运行它们
-
我实际上不知道你有什么或你想做什么,但你可能可以做到
g++ $(pkg-config ...) $(pkg-config ...) -o %e %f -
谢谢 我试过了:g++ $(pkg-config opencv4 --cflags --libs) $(pkg-config raspicam --cflags --libs) -o %e %f 但是我仍然得到错误。我想为一个项目编译opencv和raspicam。