0

I'm trying to link opencv 2.4.13 to a visual studio project. I have the .lib and .dll files in subfolders of the projects. I added the relative paths to the configuration. But I still get linking errors. My goal is to make the project portable: fi I take the directory to another machine, I will be able to run without installing opencv separately on the machine.

What I added:

  • lib subdirectory to Additional Library Directories
  • the include directories to the Additional Include Directories
  • the .dll in Linker -> Input -> Additional Dependencies

Here is an example of these errors:

LNK2019 unresolved external symbol __wcsdup_dbg referenced in function __Getctype   
LNK2001 unresolved external symbol __wcsdup_dbg 
LNK2019 unresolved external symbol __realloc_dbg referenced in function "private: static void __cdecl std::locale::_Locimp::_Locimp_Addfac(class std::locale::_Locimp *,class std::locale::facet *,unsigned int)" (?_Locimp_Addfac@_Locimp@locale@std@@CAXPAV123@PAVfacet@23@I@Z)

Any Ideas?

Amani
  • 119
  • 2
  • 13

2 Answers2

0

Make sure all your libraries are built with the same debugging configuration - that is, if you're building a DEBUG version of your project, you need to link it against the DEBUG libraries, and if you're building a RELEASE version of your project, you need to link it against the RELEASE libraries.

Likewise, you need to make sure everything else is compatible in your build options - e.g. if the libraries are built with /MT enabled, you have to also build your application with /MT enabled. Same with calling convention (/Gd, /Gr, /Gz), 32- or 64-bit, etc.

The linker errors you are getting reference _dbg symbols, which would seem to imply that you have a DEBUG/RELEASE inconsistency somewhere.

Jeff Loughlin
  • 4,134
  • 2
  • 30
  • 47
  • Thank you that seemed to solve the linkage errors. But now I have a runtime error telling me that it cannot locate the *.dll files. Do you happen to know the reason for that ? – Amani May 04 '17 at 08:21
  • Add the location of the dll files to your system PATH. – Jeff Loughlin May 04 '17 at 12:19
  • But wouldn't that defeat the purpose of including all the files in the project's folder. And would this mean that if I take the project to another computer I will have to add the dll files to the system PATH ? – Amani May 05 '17 at 06:09
0

I finally figured it out using an answer on this question: Question: OpenCV - missing dlls?

I just added the path of my dlls to Debugging Environment: Project –> Properties –> Configuration Properties –> Debugging –> Environment –> add dlls' paths here, with the following syntax:

  • For example, to prepend C:\Windows\Temp to the PATH: PATH=C:\WINDOWS\Temp;%PATH%
  • Similarly, to append $(SolutionDir)\DLLS to the PATH: PATH=%PATH%;$(SolutionDir)\DLLS
Community
  • 1
  • 1
Amani
  • 119
  • 2
  • 13