MS Visual Studio 2010: _UzpVersion is requested by object file, but _UzpVersion@0 is exported by library

StackOverflow https://stackoverflow.com/questions/18041014

Question

I'm trying to build my project using MS Visual Studio 2010 with the Info-ZIP unzip library. When I inserted UzpVersion() call into the code, the linker failed saying:

error LNK2019: unresolved external symbol _UzpVersion referenced in function _wmain

DUMPBIN shows that the library exports _UzpVersion@0 (it was compiled with the same compiler). But the object file requests _UzpVersion. The function is declared as:

extern "C" {

const UzpVer * UzpVersion(void);

}

What is wrong with it? How to fix it? Sorry, I'm not proficient with Visual C++; I spent most of my time with GNU C++.

Was it helpful?

Solution 2

Figured it out by myself.

The library is compiled with __stdcall calling convention, but does not declare exported functions as such. Visual Studio 2010 by default compiles a project with /Gd flag, that switches to __cdecl calling convention. Besides other, these calling conventions are also using different name mangling schemes for C functions.

You can read details on MSDN.

For Info-ZIP library in particular, the issue is fixed by adding the following defines before including the unzip.h header:

#define EXPENTRY __stdcall
#define USE_UNZIP_LIB

OTHER TIPS

This is a linkage error. The compiler see's the declaration of UzpVersion, otherwise, it would have failed to compile. You need to make sure you've configured your project to include the .lib.

enter image description here

EDIT: Additionally, you said you're compiling it yourself. Make sure you're compiling the sources as C and not C++.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top