I'm trying to link against ZLib, which has been built by my solution with the same respective configuration type as my project (Debug|Win32). When I build my main project, I get these unresolved symbols:
__imp__compress@16
__imp__compressBound@4
__imp__uncompress@16
If I had to guess, I would say that the @[num]
is the number of bytes for the function arguments, as that seems to line up nicely. (I have tried to search what the technical term for that suffix is, in hopes to find out how I can force the compiler to export with it, but with no luck.)
Inspecting the symbols of my zlibd.lib
, I can see all three of those symbols, except they don't have the suffix at all, nor do any other symbols in the lib.
6.zlibd.dll __imp__compress
6.zlibd.dll _compress
7.zlibd.dll __imp__compress2
7.zlibd.dll _compress2
8.zlibd.dll __imp__compressBound
8.zlibd.dll _compressBound
9.zlibd.dll __imp__crc32
9.zlibd.dll _crc32
Am I missing an option in Visual Studio to export them in that manner?
Also, I know for sure that the linker can see my zlibd.lib
, as it shows up in every search and even says at the end that it is unused.
...
Searching C:\<path-to-lib>\zlibd.lib:
...
Unused libraries:
...
C:\<path-to-lib>\zlibd.lib
If I inspect kernel32.lib
, for example, I see the @
in the symbols:
10.KERNEL32.dll __imp__AddConsoleAliasA@12
11.KERNEL32.dll _AddConsoleAliasW@12
11.KERNEL32.dll __imp__AddConsoleAliasW@12
12.KERNEL32.dll _AddDllDirectory@4
12.KERNEL32.dll __imp__AddDllDirectory@4
CodePudding user response:
@16
and @4
in the unresolved symbols mean __stdcall
calling convention when you import those symbols. Missing sign @
in zlibd.lib
means __cdecl
calling convention is used while building zlib.dll. You should use the identical calling convention while exporting and importing function.
Since you have not provided any debugging details (build settings, a minimal example), I can only guess:
- You use different compiler settings for the two projects: you maybe use
/Gz
in the app and/Gd
in the dll. Use the same compiler setting. - You do not define the macro
ZLIB_WINAPI
in the app. Add the macro definition-DZLIB_WINAPI=1
. - You define the macro
ZLIB_WINAPI
in the app. Remove the macro definition.