我收到以下链接器错误:

/tmp/cclOj2K8.o: In function `main':
fontTest.cpp:(.text+0x96): undefined reference to `cv::fontQt(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, cv::Scalar_<double>, int, int, int)'
fontTest.cpp:(.text+0x151): undefined reference to `cv::addText(cv::Mat const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Point_<int>, CvFont)'
collect2: ld returned 1 exit status

要进行编译,请输入:
gcc `pkg-config --cflags opencv` `pkg-config --libs opencv` -o fontTest fontTest.cpp

我确实安装了openCV 2.3.1。

这是我的源代码(fontTest.cpp):
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>


using namespace cv;

int main(int argc, char* argv[]) {
  Mat img1;
  CvFont font = fontQt("Times");
  addText( img1, "Hello World !", Point(50,50), font);
  imshow("image", img1);
  waitKey(0);
}

pkg-config的输出是:
-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

-I/usr/local/include/opencv -I/usr/local/include

我想念什么?

谢谢您的帮助。

最佳答案

我有同样的问题。原来,我在编译OpenCV时没有启用QT(WITH_QT = ON)。

关于qt - 对cv::fontQt的 undefined reference ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8874239/

10-09 06:37