Sunday, January 23, 2011

Undefined reference to CVKnearest...... Issue.

Hi....


People who are using OpenCV may come across this issue. This Quick and Brief post is to help those who are still struggling with this compilation problem.


Issue is "undefined reference to `CvKNearest::CvKNearest(CvMat const*, CvMat const*, CvMat const*, bool, int)' collect2: ld returned 1 exit status"

In my case, I am using OpenCV with Qt. 

Things to be checked are,
  • header file ml.h should be in your source file.
  • ml library path and the ml library should be in your project properties (if you are using Visual Studio) or in .pro file (if using Qt).
You have done above steps and still getting the same issue.. :S What should you check next ??????

This is where I got stuck. I got the exact help from OpenCV community. What he said was 
If you are trying to use with GCC the precompiled binaries of OpenCV for Windows, it won't work for C++ functionality. Have you recompiled OpenCV with GCC? C++ binaries produced by MSVC and GCC and not compatible against each other "

In my case, I had used MinGW for compiling. Now I am using MSVC and problem solved. :)


This URL helps to add MSVC compiler to a Qt project.
http://doc.qt.nokia.com/qtcreator-snapshot/creator-project-qmake.html

Have a nice DAY!!! :)

4 comments:

  1. Nice post Nadee! It will be helpful :)

    By the way, I'm using OpenCV 2.1 pre-compiled libraries for Windows with Eclipse and GCC. Still no issue came up. I'm using C. Does this happen only when we are using C++?

    OpenCV Wiki has specifically instructed developers to use CMake and compile the sources by our self if we are using an IDE other than Visual Studio. But those libs are working with Eclipe + GCC!

    Cheers!
    Dulanja

    ReplyDelete
  2. Thx Dula :D
    I think this happens for c++. Did you see this part in my post? " If you are trying to use with GCC the precompiled binaries of OpenCV for Windows, it won't work for C++ functionality ". This was given by an OpenCV Community member.
    I got above error only for ml.h file. But, cv.h, highgui.h is working well. :) Did you try ml.h with Eclipse + GCC?

    ReplyDelete
  3. Sorry I couldn't visit ur blog for some time :(

    Nope, I still didn't have to use ml ('coz I haven't done much in the project lol). I'll let you know if some errors comes up. Anyway, I probably will be coding with C.

    All the best..and write more posts ;)

    ReplyDelete
  4. Ah It's ok dear :) Even I don't often visit my blog. ;)
    He he... If I know, I'll surely help you.
    Thanks ;)

    ReplyDelete

Amazing Products