4

I have a project in QT + Opencv, the code was working but I had to format the windows and now I'm trying to import the project again and this error appeared.

undefined reference to `cv::imread(cv::String const&, int)' in this line:

 mat = cv::imread(path);

although my code looks like this:

 QString caminho = QFileDialog::getOpenFileName(this, tr("Open File"),
                                       "",
                                       tr("Images (*.png *.tiff)") );

 std::string path = caminho.toStdString();
 mat = cv::imread(path);

I tried other string like codes like "image.png" and did not work.

Using OpenCV3, QT5.4, Mingw, Windows8.1

sorry my english

vinicius
  • 73
  • 1
  • 1
  • 5

1 Answers1

1

Two notes:

  1. cv::imread works with a 'C'-like string char *. That line is like you're telling openCV to open a file called "path". You should change it to this: mat = cv::imread(path.c_str()) and it's good!

  2. undefined reference is when the compiler didn't find the implementation of that function (m.s. just posted a link about that). GCC (MinGW) is trying to look where the function 'imread' is. Since you formatted your system, you probably need to reset the environment variable 'PATH' or other configuration path. I recommend this reading: http://www.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html, it explains why you need to do it.

Hope it helps!

chaws
  • 181
  • 7
  • also currently the LoC in the question is actually `imread("path")` which doesn't even use the path variable set on the line before. – GPPK May 19 '15 at 14:54
  • I wrote wrong, actually is `imread(path)`; without quotes. And I tried to 'path.c_str ()' and not worked. Strange compiler shows cv::String although used 'std::String' – vinicius May 20 '15 at 03:58
  • My bad, this is the C++ implementation which uses string indeed. I used Linux when I did openCV classes, but this tutorial seems to be useful for your case: https://zahidhasan.wordpress.com/2014/08/19/qt-5-3-1-64-bit-mingw-windows/ – chaws May 20 '15 at 16:58