简体   繁体   English

使用Visual Studio 2008从x86编译x64 dll

[英]Compiling x64 dll from x86 using Visual Studio 2008

I am compiling some external C++ code into a dll using Visual Studio 2008. The code is wrapped in extern "C". 我正在使用Visual Studio 2008将一些外部C ++代码编译到dll中。代码被包装在外部“ C”中。

Since I am cross compiling, creating a 64 bit dll on my 32 bit machine; 由于我正在交叉编译,因此请在32位计算机上创建一个64位dll。 I am using x64 as "Active solution platform" in the "Configuration Manager". 我将x64用作“配置管理器”中的“活动解决方案平台”。

My dll compiles and links successfully. 我的dll编译并成功链接。 However when I open it in Dependency Walker (depends.exe) I notice something strange: My dll is marked as 64 bit. 但是,当我在Dependency Walker(depends.exe)中打开它时,我发现有些奇怪:我的dll被标记为64位。 My dll however depends on C:\\windows\\system32\\ntdll.dll and C:\\windows\\system32\\kernel32.dll which are 32 bit! 但是,我的dll取决于32位的C:\\ windows \\ system32 \\ ntdll.dll和C:\\ windows \\ system32 \\ kernel32.dll! As a result Dependency Walker gives me the following errors: "Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module. Error: Modules with different CPU types were found." 结果,Dependency Walker给了我以下错误:“错误:由于隐式依赖模块中缺少导出功能,至少一个模块的导入无法解析。错误:找到了具有不同CPU类型的模块。”

What is going wrong here? 这是怎么了?

Thanks in advance for any answers! 预先感谢您的任何回答!

Dependency walker gives you that error because the dll files in system32 on your 32 bit system are 32 bits. Dependency Walker会给您该错误,因为32位系统system32的dll文件是32位。 If you run it on a 64 bit version of Windows it will work fine. 如果您在64位版本的Windows上运行它,它将可以正常工作。

Perhaps the misunderstanding comes from the name of system32 ? 也许误会来自于system32的名称? It doesn't necessarily contain 32 bit files - it contains files matching the bit size of the operating system, so on 32 bit Windows sytem32 contains 32 bit dlls, and on 64 bit Windows system32 contains 64 bit dlls. 它不一定包含32位文件-它包含与操作系统的位大小匹配的文件,因此在32位Windows sytem32包含32位dll,在64位Windows system32包含64位dll。

It gets more complicated though - 64 bit Windows can run 32 bit processes, and if a 32 bit process accesses system32 on a 64 bit version of Windows, that access it gets redirected to the SysWOW64 (yes system32 contains 64 bit dlls and SysWOW64 contains 32 bit dlls). 但是,它变得更加复杂-64位Windows可以运行32位进程,并且如果32位进程在64位版本的Windows上访问system32,则将其重定向到SysWOW64 (是的system32包含64位dll,而SysWOW64包含32位dll)。

Your DLL depends on ntdll.dll and kernel32.dll . 您的DLL取决于ntdll.dllkernel32.dll Dependency Walker tries to find them according to lookup rule of the LoadLibrary function. Dependency Walker尝试根据LoadLibrary函数的查找规则找到它们。 And it finds them in system32 directory, but on 32-bit system they are 32-bit. 它在system32目录中找到它们,但是在32位系统上,它们是32位。

Use 64 bit version of Dependency Walker to open your 64 bit version of dll's. 使用Dependency Walker的64位版本打开DLL的64位版本。 You will no longer see the error message, "Error: Modules with different CPU types were found", if your modules are properly compiled for x64. 如果您的模块已针对x64正确编译,您将不再看到错误消息“错误:找到了具有不同CPU类型的模块”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM