未定义的引用cv :: fontQt

时间:2012-01-15 23:15:56

标签: qt opencv

我收到以下链接器错误:

/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  

我错过了什么?

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

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