c++ - 未定义对 `main' 的引用 - 但包含主要功能

标签 c++ linux opencv program-entry-point undefined-reference

<分区>

我在尝试编译我的代码时遇到以下错误:

/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;
}

是什么导致了这个错误?

最佳答案

如错误消息所述:您没有main 函数。他们必须具有以下签名之一:

int main()

int main(int, char**)

关于c++ - 未定义对 `main' 的引用 - 但包含主要功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21384575/

相关文章:

c++ - 使用 std::chrono::duration 跟踪超时

c++ - qt C++信号与槽中删除函数错误的使用

linux - 使用来自文本和空行的数据创建 .csv

linux - bash 脚本中 if 条件中的算术运算符无效

linux - 有什么好的方法可以让像 D-Bus 这样的东西在多台 Linux 机器上工作,可能通过防火墙?

c++ - 使用 C++ 在 Qt3D 中创建多个视口(viewport)的问题

c++ - 使用 char * 和字符串类反转字符串

python - OpenCV 网络摄像头问题

OpenCV:cvCloneImage 和内存泄漏

iphone - iPhone照片微笑操作应用程序