[英]program comiled ok using pkg-config --cflgas opencv and pkg-config --ldflag but not executable (ubuntu 16.04)
Recently I installed opencv on my ubuntu 16.04 machine(I've done this many times before and used it ok).最近我在我的 ubuntu 16.04 机器上安装了 opencv(我以前做过很多次并且使用它)。 I tried compiling yolo program, it compiled ok and ran ok.
我尝试编译 yolo 程序,它编译正常并且运行正常。 When I set OPENCV=1 in the Makefile, it compiles the program with opencv.
当我在 Makefile 中设置 OPENCV=1 时,它会用 opencv 编译程序。 To set the compile and link flags it has these two lines.
要设置编译和链接标志,它有这两行。
LDFLAGS+= `pkg-config --libs opencv` -lstdc++
COMMON+= `pkg-config --cflags opencv`
My pkg-config commands work correctly.我的 pkg-config 命令工作正常。 See the output below.
请参阅下面的输出。
ckim@chan-ubuntu:~/YOLOV2/darknet$ pkg-config --cflags opencv
-I/home/ckim/opencv_install/installation/OpenCV-3.4/include/opencv -I/home/ckim/opencv_install/installation/OpenCV-3.4/include
ckim@chan-ubuntu:~/YOLOV2/darknet$ pkg-config --libs opencv
-L/home/ckim/opencv_install/installation/OpenCV-3.4/lib -lopencv_stitching -lopencv_videostab -lopencv_superres -lopencv_surface_matching -lopencv_dnn_objdetect -lopencv_line_descriptor -lopencv_aruco -lopencv_img_hash -lopencv_xobjdetect -lopencv_dpm -lopencv_freetype -lopencv_stereo -lopencv_face -lopencv_objdetect -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_saliency -lopencv_hfs -lopencv_ccalib -lopencv_tracking -lopencv_datasets -lopencv_plot -lopencv_optflow -lopencv_ximgproc -lopencv_fuzzy -lopencv_bioinspired -lopencv_highgui -lopencv_videoio -lopencv_text -lopencv_dnn -lopencv_reg -lopencv_hdf -lopencv_bgsegm -lopencv_rgbd -lopencv_sfm -lopencv_xfeatures2d -lopencv_calib3d -lopencv_shape -lopencv_imgcodecs -lopencv_features2d -lopencv_video -lopencv_ml -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
A couple of days ago, I tried compiling a simple opencv pgrogram that I find on a web page and tried compiling it.几天前,我尝试编译我在网页上找到的一个简单的 opencv pgrogram 并尝试编译它。 (Iwanted to test a basic display window's behavior).
(我想测试一个基本的显示窗口的行为)。 The program was like this.
节目是这样的。 very typical)
很典型)
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(1); // Wait for a keystroke in the window
return 0;
}
When I compile and link it with command当我编译并用命令链接它时
gcc -c test.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv` -o test
it gives me no error and I see the file test
but it's not executable.它没有给我任何错误,我看到了文件
test
但它不是可执行文件。 When I run it after setting chmod +x test
, I get当我在设置
chmod +x test
后运行它时,我得到
ckim@chan-ubuntu:~/opencvtest$ ./test
bash: ./test: cannot execute binary file: Exec format error
ckim@chan-ubuntu:~/opencvtest$ file test
test: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
What could be wrong?可能有什么问题?
As per the comment you're command line...根据评论,您是命令行...
gcc -c test.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv` -o test
includes the -c
flag which tells the compiler to compile only -- don't link.包括
-c
标志,它告诉编译器只编译——不要链接。 Also.还。 as you're code is
c++
rather than c
you need to link with the correct runtime libraries.由于您的代码是
c++
而不是c
您需要链接正确的运行时库。 That means using g++
rather than gcc
.这意味着使用
g++
而不是gcc
。 So the command should be...所以命令应该是...
g++ test.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv` -o test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.