C语言 如何使用 Visual Studio 2010 编译 64 位的 C DLL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3060452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 05:40:59  来源:igfitidea点击:

How to compile a C DLL for 64 bit with Visual Studio 2010?

cvisual-studio-2010dllimport32bit-64bit

提问by Daren Thomas

I have a DLL written in C in source code. This is the code for the General Polygon Clipper(in case you are interested). I'm using it in a C# project via the C# wrapper provided on the homepage. This comes with a precompiled DLL.

我在源代码中有一个用 C 编写的 DLL。这是General Polygon Clipper的代码(如果您有兴趣的话)。我通过主页上提供的 C# 包装器在 C# 项目中使用它。它带有一个预编译的 DLL。

Since switching to a 64bit Development machine with Visual Studio 2010 and Windows 7 64 bit, the application won't run anymore. This is the error I get:

由于切换到具有 Visual Studio 2010 和 Windows 7 64 位的 64 位开发机器,该应用程序将不再运行。这是我得到的错误:

An attempt was made to load a program with an incorrect format.

试图加载格式不正确的程序。

This is because of DLLImporting the 32bit gpc.dll, as I have gathered from stuff found on the web.

这是因为DLLImport32bit gpc.dll,因为我是从网上找到的东西中收集的。

I assume this will all go away if I recompile the DLL to 64bit, but can't for the love of me figure out how to do so. My C skills are basic, in that I can write a C program with the GNU tools, but have no experience with various compilers / processors / IDEs etc.

我认为如果我将 DLL 重新编译为 64 位,这一切都会消失,但我无法弄清楚如何这样做。我的 C 技能是基本的,因为我可以使用 GNU 工具编写 C 程序,但没有使用各种编译器/处理器/IDE 等的经验。

I believe I could port this to C#. By that I mean I trust myself to actually pull it off. But I'd prefer not to, since it is a lotof work that I'd prefer a compiler to do for me ;)

我相信我可以将它移植到 C#。我的意思是我相信自己会真正做到这一点。但我不想这样做,因为我更希望编译器为我做很多工作;)

采纳答案by Daren Thomas

It could be as easy as creating a new platform:

就像创建一个新平台一样简单:

  • open property pages of project (ALT+ENTER)
  • choose platform x64in dropdown menu in top-right corner
    • if the platform does not already exist, create a new one
  • rebuild
    • make sure you are checking the right artefacts when built, as you now probably have a different output directory.
  • 打开项目的属性页(ALT+ENTER)
  • 在右上角的下拉菜单中 选择平台x64
    • 如果平台尚不存在,请创建一个新平台
  • 重建
    • 确保在构建时检查正确的人工制品,因为您现在可能有不同的输出目录。