C++ 通过.def文件导出函数时,如何使用dllImport导入函数?
我很难将Minizip()示例源代码编译到Windows中的控制台应用程序中 在尝试构建minizip.c示例时,我遇到以下错误:C++ 通过.def文件导出函数时,如何使用dllImport导入函数?,c++,visual-studio,dll,zlib,C++,Visual Studio,Dll,Zlib,我很难将Minizip()示例源代码编译到Windows中的控制台应用程序中 在尝试构建minizip.c示例时,我遇到以下错误: Error 9 error LNK2019: unresolved external symbol _zipClose referenced in function _main C:\tst_create_zip\tst_create_zip\tst_create_zip.obj Error 13 error LNK2019: unresolve
Error 9 error LNK2019: unresolved external symbol _zipClose referenced in function _main C:\tst_create_zip\tst_create_zip\tst_create_zip.obj
Error 13 error LNK2019: unresolved external symbol _zipOpen2_64 referenced in function _main C:\tst_create_zip\tst_create_zip\tst_create_zip.obj
我在zip.h中看到,函数是用extern“C”和uu cdecl调用约定导出的,因此链接器希望函数具有某种C样式的名称(总是包含下划线“u”)
zlibwapi.dll(包含zLib和Minilib)的依赖项walker显示,导出函数时不带下划线,如“zipClose”、“_zipOpen2_64”
所以问题是:如何告诉链接器搜索没有下划线的函数名?或者我应该改用LoadLibrary()吗
提前谢谢。原来我缺少一条预处理器指令
#ifdef ZLIB_WINAPI
#include <windows.h>
// No need for _export, use ZLIB.DEF instead.
// For complete Windows compatibility, use WINAPI, not __stdcall.
#define ZEXPORT WINAPI
#ifdef ZLIB_WINAPI
#包括
//不需要导出,请改用ZLIB.DEF。
//要实现完全的Windows兼容性,请使用WINAPI,而不是stdcall。
#定义ZEXPORT WINAPI
当我定义ZLIB_WINAPI时,它起了作用
有一件事误导了我的理解,那就是在函数声明之前没有_declspec(dllexport)。然而,链接器能够解析导入。您只是忘记了链接zlib导入库。您必须首先构建它,然后是Project+属性、链接器、输入和其他依赖项。@HansPassant I仔细检查,zlibwapi.lib被列为其他依赖项。还有其他想法吗?