为什么cl.exe无法生成有效的Windows模块? [英] Why isn't cl.exe producing a valid Windows module?

查看:172
本文介绍了为什么cl.exe无法生成有效的Windows模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的C DLL,它公开了静态库中的函数. DLL编译没有错误,我可以在其上运行DUMPBIN以查看导出.但是,当我尝试用C#中的DllImport加载它时,它会说:

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:无法加载DLL'ei.dll':找不到指定的模块. (来自HRESULT的异常:0x8007007E).

System.DllNotFoundException: Unable to load DLL 'ei.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E).

当然,它在正确的目录中.因此,我读到,如果需要添加其他内容,尝试Dependency Walker可能是一个好主意.不幸的是,当我尝试在DW中打开DLL时,我得到了:

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:

错误:至少一个文件不是32位或64位Windows模块.

Error: At least one file was not a 32-bit or 64-bit Windows module.

这是我的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

这可能是什么原因造成的?

What could be causing this?

推荐答案

我正在链接一个名称与编译器发出的LIB文件相同的LIB文件,因此它正在与自身链接.我只是将源文件的名称更改为ErlInterface.c.我认为链接器会在发生这种情况时抛出警告或其他内容,但事实并非如此.

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.

无论如何,我现在可以在Dependency Walker中打开DLL,但是我仍然不能在DllImport中使用它.不过,这是另一个问题.

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.

这篇关于为什么cl.exe无法生成有效的Windows模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆