简体   繁体   English

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

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

I have a DLL written in C in source code. 我在源代码中用C编写了一个DLL。 This is the code for the General Polygon Clipper (in case you are interested). 这是General Polygon Clipper的代码(如果您感兴趣的话)。 I'm using it in a C# project via the C# wrapper provided on the homepage. 我通过主页上提供的C#包装器在C#项目中使用它。 This comes with a precompiled DLL. 这附带一个预编译的DLL。

Since switching to a 64bit Development machine with Visual Studio 2010 and Windows 7 64 bit, the application won't run anymore. 由于使用Visual Studio 2010和Windows 7 64位切换到64位开发机器,应用程序将不再运行。 This is the error I get: 这是我得到的错误:

An attempt was made to load a program with an incorrect format. 尝试加载格式不正确的程序。

This is because of DLLImport ing the 32bit gpc.dll , as I have gathered from stuff found on the web. 这是因为DLLImport是32位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. 我假设如果我将DLL重新编译为64位,这将全部消失,但不能因为我的爱而弄清楚如何这样做。 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. 我的C技能是基本的,因为我可以用GNU工具编写C程序,但没有使用各种编译器/处理器/ IDE等经验。

I believe I could port this to C#. 我相信我可以把它移植到C#。 By that I mean I trust myself to actually pull it off. 我的意思是我相信自己实际上把它拉下来了。 But I'd prefer not to, since it is a lot of work that I'd prefer a compiler to do for me ;) 但我不愿意,因为我需要编译器为我做很多工作;)

It could be as easy as creating a new platform: 它可以像创建新平台一样简单:

  • open property pages of project (ALT+ENTER) 打开项目属性页(ALT + ENTER)
  • choose platform x64 in dropdown menu in top-right corner 在右上角的下拉菜单中选择平台x64
    • 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. 确保在构建时检查正确的伪像,因为您现在可能有不同的输出目录。

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

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