【发布时间】:2014-02-18 12:15:40
【问题描述】:
我在尝试编译我的代码时收到以下错误:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
我正在使用以下命令:
g++ detectTemplatePoints.cpp -o SURF_TemplatePoints `pkg-config --cflags --libs opencv`
从我在网上可以找到的内容来看,这似乎发生在您没有包含 main 入口点但我确实拥有它时,我的代码如下:
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
void readme();
int main (int argc, char* argv[]) {
if( argc != 2 ) {
readme(); return -1;
}
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_1.data ) {
std::cout<< " --(!) Error reading images " << std::endl; return -1;
}
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1;
detector.detect( img_1, keypoints_1 );
Mat img_keypoints_1;
drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
imshow("Keypoints 1", img_keypoints_1 );
waitKey(0);
return 0;
}
void readme() {
std::cout << " Usage: ./detectTemplatePoints <img1>" << std::endl;
}
是什么导致了这个错误?
【问题讨论】:
-
这不可能是你的完整代码,还有更多的东西,问题可能就在那里(就像一个宏发狂)
-
第四行return -1的目的是什么?
-
pkg-config --cflags --libs opencv输出什么? -
@Colin747 嗯...对不起,如果这个太明显了,但我知道它以前发生在我身上,所以无论如何我都会问它。您是否有任何机会编辑了错误的文件?也就是说,“坏目录”上的文件实际上是一个没有 main 方法的旧版本,并且您不小心编辑了另一个文件,认为它是
detectTemplatePoints.cpp,而实际上它不是? -
我讨厌这种情况。当我有一个 SO 问题时,我更讨厌它。 :(
标签: c++ linux opencv main undefined-reference