为什么 cl.exe 没有生成有效的 Windows 模块?
我有一个简单的 C DLL,它公开静态库中的函数。 DLL 编译时没有错误,我可以在其上运行 DUMPBIN 以查看导出。但是,当我尝试在 C# 中使用 DllImport
加载它时,它会显示以下内容:
System.DllNotFoundException:无法加载 DLL“ei.dll”:找不到指定的模块。 (HRESULT 异常:0x8007007E)。
当然,它位于正确的目录中。因此,我读到尝试 Dependency Walker 可能是个好主意,以防我需要包含其他内容。不幸的是,当我尝试在 DW 中打开 DLL 时,我得到以下信息:
错误:至少有一个文件不是 32 位或 64 位 Windows 模块。
这是我的 cl
命令:
set ERL_INTERFACE_DIR=C:\Progra~1\erl5.7.2\lib\erl_interface-3.6.2\
call vcvars32.bat
cl /I%ERL_INTERFACE_DIR%include /LD ei.c ei.lib Ws2_32.lib /link /LIBPATH:%ERL_INTERFACE_DIR%lib
可能是什么原因导致的?
I have a simple C DLL that exposes functions from a static library. The DLL compiles without errors and I can run DUMPBIN on it to see the exports. However, when I attempt to load it with DllImport
in C#, it says this:
System.DllNotFoundException: Unable to load DLL 'ei.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E).
It's in the correct directory, for sure. So, I read that it might be a good idea to try Dependency Walker, in case I need to include something else. Unfortunately, when I try to open my DLL in DW, I get this:
Error: At least one file was not a 32-bit or 64-bit Windows module.
Here's my cl
command:
set ERL_INTERFACE_DIR=C:\Progra~1\erl5.7.2\lib\erl_interface-3.6.2\
call vcvars32.bat
cl /I%ERL_INTERFACE_DIR%include /LD ei.c ei.lib Ws2_32.lib /link /LIBPATH:%ERL_INTERFACE_DIR%lib
What could be causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在链接一个 LIB 文件,该文件的名称与编译器发出的 LIB 文件相同,因此它正在与自身链接。我刚刚将源文件的名称更改为 ErlInterface.c。我认为发生这种情况时链接器会发出警告或其他内容,但事实并非如此。
无论如何,我现在可以在 Dependency Walker 中打开 DLL,但仍然无法通过
DllImport
使用它。不过,这是另一个问题。I was linking with a LIB file whose name is the same as the LIB file that the compiler emits, so it was linking with itself. I just changed the name of my source file to ErlInterface.c. I would think the linker would throw up a warning or something when this happens, but it doesn't.
Anyway, I can open the DLL in Dependency Walker now, but I still can't use it with
DllImport
. That's for another question, though.