简体   繁体   English

在 MS VC 2013 Express 中将 C++ dll 从 32 位转换为 64 位

[英]Convert C++ dll from 32bit to 64bit in MS VC 2013 Express

My code can be compiled in both of 32 and 64bit configuration but only the first one works well.我的代码可以在 32 位和 64 位配置下编译,但只有第一个运行良好。 I opened the libraries with depends.exe and in case of 64bit I see two error messages:我用depends.exe打开了库,在64位的情况下,我看到两条错误消息:

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.错误:找到具有不同 CPU 类型的模块。

In the depends.exe's module list I see the CPU type of my dll is x64 but everything else is x86 (everything else supposed to be dynamically linked).在depends.exe 的模块列表中,我看到我的dll 的CPU 类型是x64,但其他一切都是x86(其他一切都应该是动态链接的)。 How can I tell to the VC to use 64bit libraries in case of dynamic linking?在动态链接的情况下,如何告诉 VC 使用 64 位库?

There is no warning or error message during the compiling and linking.编译和链接期间没有警告或错误消息。

Considering the configuration I configured my solution according to MS suggestions and I think there is nothing wrong with that.考虑到配置,我根据 MS 的建议配置了我的解决方案,我认为这没有任何问题。 I can only think for missing macros or wrong lib dependencies or maybe VC options.我只能考虑缺少宏或错误的库依赖项,或者可能是 VC 选项。

EDIT: This is very close to my problem.编辑: 非常接近我的问题。

EDIT2: In case of the lib I also get error message: Error: At least one file was not a 32-bit or 64-bit Windows module. EDIT2:如果是 lib,我也会收到错误消息:错误:至少一个文件不是 32 位或 64 位 Windows 模块。 And No DOS or PE signature found.并且没有找到 DOS 或 PE 签名。 This file is not a valid 32-bit or 64-bit Win module.此文件不是有效的 32 位或 64 位 Win 模块。

This sort of message from Dependency Viewer is often a red herring, a false positive.来自 Dependency Viewer 的这类消息通常是一个红鲱鱼,一个误报。 If you use the 32 bit version of Dependency Walker with a 64 bit module, it can sometimes think, mistakenly, that your DLL links to 32 bit modules.如果您将 32 位版本的 Dependency Walker 与 64 位模块一起使用,它有时会错误地认为您的 DLL 链接到 32 位模块。

You can try instead to use the 64 bit version of Dependency Walker which should work better.您可以尝试改用 64 位版本的 Dependency Walker,它应该可以更好地工作。 However, Dependency Walker is doing a static analysis that does not always yield the same results as the true module loader.然而,Dependency Walker 正在做一个静态分析,它并不总是产生与真正的模块加载器相同的结果。 If you want to know whether your module can load, you need to get the loader to load it in a running program.如果你想知道你的模块是否可以加载,你需要让加载器在一个正在运行的程序中加载它。 For instance by creating a program that links to the DLL.例如,通过创建链接到 DLL 的程序。

The simplest way to do that is to create a simple program that calls LoadLibrary to load the library.最简单的方法是创建一个调用LoadLibrary来加载库的简单程序。 See if that succeeds or not.看看能不能成功。 If not then you likely have problems with dependencies.如果不是,那么您可能会遇到依赖关系问题。 They are best debugged using Dependency Walker's profile mode.它们最好使用 Dependency Walker 的配置文件模式进行调试。 That debugs the load process dynamically rather than the error-prone static analysis that you have been using.这会动态调试加载过程,而不是您一直在使用的容易出错的静态分析。

Of course, it is certainly possible that your DLL will fail to load because the loader comes up with 32 bit DLLs when resolving dependencies.当然,您的 DLL 肯定有可能无法加载,因为加载器在解析依赖项时会提供 32 位 DLL。 If that is the case then profile mode of Dependency Viewer will reveal the problem and then you can tackle it.如果是这种情况,那么 Dependency Viewer 的配置文件模式将揭示问题,然后您可以解决它。

Regarding your question edits, a .lib file is not a PE module.关于您的问题编辑,.lib 文件不是 PE 模块。 You cannot pass a .lib file to LoadLibrary , or inspect it with Dependency Walker.您不能将 .lib 文件传递​​给LoadLibrary ,也不能使用 Dependency Walker 检查它。 Perhaps some of the confusion arises because the term library is overloaded.可能会出现一些混淆是因为术语超载了。 A .lib file is a library, either an import library or a static library. .lib 文件是一个库,可以是导入库或静态库。 And a DLL is a library, a dynamic link library. DLL 是一个库,一个动态链接库。 In what I wrote above, I used library to refer to DLLs.在我上面写的内容中,我使用 library 来引用 DLL。

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

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