Problem linking against OpenCV C++ API
Hi all,
I'm programming simple apps that work with OpenCV. My problem is that when I compile any code that uses the cv::findContours(), cv::drawContours, cv::imwrite() or any of the functions that have a vector<> as parameter, the linker throws me an "undefined reference" error for the function. I have checked eveything I can, such as: 1) Correct declaration of parameters and calling of the functions. 2) Checked that the functions are declared on the OpenCV headers and defined in the source code. 3) I even made an objdump of the .so files to see if the functions were compiled in. This is one of the apps that are causing me trouble: Code:
#include "cv.h" Code:
c++ -I/usr/include/opencv -lcv -lhighgui -o pic pic.cpp Code:
... Thank you all ;-) |
This works (compiles and links) fine for me. What is the output of:
Code:
readelf -Ws /usr/lib/libhighgui.so | grep imwrite Evo2. |
Quote:
Code:
833: 00017850 41 FUNC GLOBAL DEFAULT 11 _ZN2cv7imwriteERKSsRKNS_3MatERKNSt9__cxx19986vectorIiSaIiEEE Thank you very much! |
Quote:
Thanks and regards, |
Evo, If you dont mind me asking, which version of OpenCV are you using? I'm on version 2.0.0-r1.. Thanks
|
The output of the command "nm -DC /usr/lib/libhighgui.so | grep imwrite" is:
Code:
00017850 T cv::imwrite(std::string const&, cv::Mat const&, std::__cxx1998::vector<int, std::allocator<int> > const&) I have no clue of why i'm having a problem only with some of the functions when the others work just fine.. |
did you ever figure out the problem?
I got the same one. |
Quote:
Evo2. |
Quote:
Let me know if you figure this out.. Germán |
The problem was solved using the latest version (haven't been released yet when I came up with this issue). With OpenCV version 2.1 (releases in April 2010), this doesn't happen to me anymore.
Thank you all for your help! ;) |
Same problem here with OpenCV 2.1
Hi there,
I think I am running into the same issue, but with OpenCV 2.1! For me, using cv::Mat is not problem, but functions like cv::imread or cv::namedWindow cause the "undefined reference" error message. And, surprisingly, all was running perfect as long as I was using the C API of OpenCV. Only when I started to use the C++ API, the problems started. Has anybody an idea what could be the problem here? I am linking to cv210, highgui210, cvaux210 and cxcore210. Am I missing something here? Thanks |
Looks like the wrong libs are being found at runtime. Have you checked the output of ldd on the executable? Does it show the libs you expect?
Evo2. |
Hi Evo2,
Thanks for your hint. I thought that it is impossible that I link the wrong libraries, since it is the first time I am working with OpenCV and therefore have only one version istalled. But you were right! I was linking the libraries in C:\OpenCV2.1\bin, and there were really some libraries with the correct name in this directory, but not the ones that I compiled myself (file creation timestamp was too old). Finally I found that my compiled libs were going to C:\OpenCV2.1\CMakeFiles\bin (This depends on your actual CMake configuration!). Now linking to this directory, it works fine :-) Also I hope I won't be banned now since I am working on windows... Thanks, Pingulinli |
Hi again,
I was cheering too soon... Although compilation and linking do not produce an error message anymore, I have now the following problem: As soon as I try to open a named window (e.g. cv::namedWindow("Display", CV_WINDOW_AUTOSIZE);) the application crashes (Application has encountered a problem and needs to close...). But, surprisingly, the Window is opening with the correct name "Display" before the application crashes! Other functions of the OpenCV library seem to work, e.g. creating a cv::Mat and then loading an image to it by imread(argv[1], 1); Is this another linker problem? Unfortunately when debugging in Eclipse, I can only see that it crashes at the namedWindow function call, but I cannot jump into it (but anyway I am not sure if that would be of any help to me...) Regards, Pingulinli PS. Here is what Dependency Walker outputs when profiling the crashing application: [...] GetProcAddress(0x75250000 [MSCTFIME.IME], "ImeGetImeMenuItems") called from "IMM32.DLL" at address 0x76337354 and returned NULL. Error: The procedure was not found (127). GetProcAddress(0x75250000 [MSCTFIME.IME], "CtfImeInquireExW") called from "IMM32.DLL" at address 0x76337394 and returned 0x75269548. GetProcAddress(0x75250000 [MSCTFIME.IME], "CtfImeSelectEx") called from "IMM32.DLL" at address 0x763373A8 and returned 0x752692C5. GetProcAddress(0x75250000 [MSCTFIME.IME], "CtfImeEscapeEx") called from "IMM32.DLL" at address 0x763373BC and returned 0x752696FE. GetProcAddress(0x75250000 [MSCTFIME.IME], "CtfImeGetGuidAtom") called from "IMM32.DLL" at address 0x763373D0 and returned 0x75269737. GetProcAddress(0x75250000 [MSCTFIME.IME], "CtfImeIsGuidMapEnable") called from "IMM32.DLL" at address 0x763373E4 and returned 0x7526931A. Second chance exception 0xC0000005 (Access Violation) occurred in "LIBHIGHGUI210.DLL" at address 0x6A3350C4. Exited "TESTE.EXE" (process 0x98C) with code -1073741819 (0xC0000005). |
Hi
I think I have now finally a working OpenCV environment (after hours and hours of trying all kind of stuff...) In short, the solution was to use the gcc version 4.4.1, which I downloaded here: http://sourceforge.net/downloads/tdm...vious/1.908.0/ Download tdm-mingw-1.908.0-4.4.1-2.exe and install it. Do not use the web installer since this will download the latest version (which gave me the troubles described above). Then compile OpenCV 2.1 as described in the instructions, using CMake etc. After this I am now able to use the C interface (e.g. cvLoadImage) as well as the C++ interface (e.g. cv::imread). When I tried to use the windows binarys (dll's) of the OpenCV library which can be downloaded from the OpenCV website (OpenCV-2.1.0-win32-vs2008.exe), I can use the C interface but not the C++ interface. Using the C++ interface will give a Linker error as described in my previous posts. I assume this is due to some incompatible name mangling for the C++ functions in the dlls. When I compiled OpenCV 2.1 with TDM-GCC 4.5, everything was compiling and linking fine, but the cv::namedWindow crashed everytime it was called! I assume this is a bug in OpenCV which is only visible with this new compiler. I hope this helps some people so they do not have to go through all the frustration that I went through! BTW, I am working with Eclipse Helios with CDT plugin, on Windows XP SP2. Best Regards, Pinguinli |
All times are GMT -5. The time now is 11:38 AM. |