NERL
NERL

Reputation: 302

How to get rid of LNK2019 unresolved external symbol errors with opencv and vs2012

I'm a visual basic programmer trying to get a visual c++ up and running with some source code I found that uses OpenCV. I'm not very experienced at all with c++. I'm getting unresolved external symbol errors and I've spent hours reading every article I can find on here about it, and every answer is... "don't link x86 with x64 libs, or vise versa" or "add x references to preferences->linker" or "add your lib/dll files to the project folder, and then add them to your solution" or "obviously you didn't add the libs to your linker".

I've already done all of the following, and it didn't work...

1) I added "c:\opencv\build\x64\vc11\staticlib;%(AdditionalLibraryDirectories)" to my "Additional Library Directories" in Project->Preferences->Linker->General. Didn't help a bit.

2) I tried the above with the x86 directory instead, didn't help a bit. So the theories that it's a x64 / x86 problem doesn't seem to be the answer.

3) I added "opencv_calib3d244d.lib;opencv_contrib244d.lib;opencv_core244d.lib;opencv_features2d244d.lib;opencv_flann244d.lib;opencv_gpu244d.lib;opencv_haartraining_engined.lib;opencv_highgui244d.lib;opencv_imgproc244d.lib;opencv_legacy244d.lib;opencv_ml244d.lib;opencv_nonfree244d.lib;opencv_objdetect244d.lib;opencv_photo244d.lib;opencv_stitching244d.lib;opencv_ts244d.lib;opencv_video244d.lib;opencv_videostab244d.lib;%(AdditionalDependencies)" to my Project->Preferences->Linker->Input, for Debug(active). Didn't help.

4) I tried the above with the "lib" directory instead of the "staticlib" directory. Didn't help a bit.

5) I tried copying all the debug version of the *.lib files from the lib directory into my project folder, and Project->Add->Existing Item to add them to my project. Didn't help.

6) I added "c:\opencv\build\include;%(AdditionalIncludeDirectories)" to my Project->Preferences->C/C++->General->Additional Include Directories. Didn't help.

It does not appear to be any of these things. Does anyone know a solution to this error that does not involve any of these things I already tried?

Here are some of the errors I'm getting:

Error 16 error LNK2019: unresolved external symbol _cvCreateImage referenced in function "struct _IplImage * __cdecl loadFloatImage(char const *)" (?loadFloatImage@@YAPAU_IplImage@@PBD@Z) C:\dev\CPP_console\CPP_console\FeaturesMain.obj CPP_console Error 17 error LNK2001: unresolved external symbol _cvCreateImage C:\dev\CPP_console\CPP_console\TextDetection.obj CPP_console Error 18 error LNK2019: unresolved external symbol _cvReleaseImage referenced in function "struct _IplImage * __cdecl loadFloatImage(char const *)" (?loadFloatImage@@YAPAU_IplImage@@PBD@Z) C:\dev\CPP_console\CPP_console\FeaturesMain.obj CPP_console

Upvotes: 1

Views: 6170

Answers (1)

NERL
NERL

Reputation: 302

I found the solution. VS2012 is glitched. I thought my project was set to x64, because when I clicked on Build -> Configuration Manager -> Platform, there was no other option for platform except "Win32" and "Edit". When I clicked "Edit", it said that the platform was x64, but that it had copied settings from "Win32". This appears to be a glitch in VS2012. Fact is, I was NOT editing the current platform, even though I was clicking the "edit" button. Rather, it was creating a NEW platform. But because I had clicked the edit button, I thought it was telling me that my platform was x64, because that's what it had selected. But no, it was creating a new platform... and it really should not say that the project could be x64, yet copying settings from Win32! Anyway, so multiple glitches appear to be there in VS2012. So to fix my problem, I had to click the "edit" link, and tell it to copy settings from "" instead of from Win32 (blank is the only other option). This created a new platform option called x64, and changed it to show that my platform was now x64. Also, doing this magically made a button called "new" appear next to the "edit" button in the platform drop-down, and the "edit" button no longer acts like a new button (it no longer gives the option to "copy settings from __". But the "new" button still allows you to create a x64 platform, yet copy settings from Win32, which is stupid. But at least now when I click edit, it actually acts a bit more like an edit button. VS2012 is bugged in this menu area. Anyway, all my link errors went away when I got it fully changed to x64, since I am using a x64 version of OpenCV. If anyone else is using an x64 version of OpenCV: make sure your "Platform" says x64, not Win32, or it will give your LNK errors.

Upvotes: 2

Related Questions