简体   繁体   English

如何创建一个使用CLR混合C和C ++的Visual Studio项目?

[英]How can I create a single Visual Studio project that mixes C and C++ using CLR?

I am working on porting code that builds on GCC on Unix to windows using Visual Studio 2008. I would like to create a single executable that does not depend on any dll(s) of my own creation and only built in ones to the Windows operating system. 我正在使用Visual Studio 2008将基于GCC构建的代码移植到Windows上。我想创建一个不依赖于我自己创建的任何dll的单个可执行文件,而只是内置于Windows操作系统的可执行文件系统。

My code includes zlib which itself includes C files which I can build and link fine into my Unix executable. 我的代码包括zlib,它本身包含我可以构建的C文件,可以很好地链接到我的Unix可执行文件中。

In my beginning attempts to build, the first error I hit is that the C code from zlib cannot be built with CLR since it is not C++. 在我开始尝试构建时,我遇到的第一个错误是zlib的C代码无法使用CLR构建,因为它不是C ++。

I see some suggesting to break this out into a separate DLL which would be linked into my executable but I'd like to avoid the complexity of shared libraries if possible. 我看到有人建议将其分解为一个单独的DLL,它将链接到我的可执行文件中,但我希望尽可能避免共享库的复杂性。 (Perhaps this avoidance is even more complex?) (也许这种回避更复杂?)

Is there a way to mix my C++ with the C code of zlib into a single executable with CLR? 有没有办法将我的C ++与zlib的C代码混合成CLR的单个可执行文件?

My current build error is the following: 我当前的构建错误如下:

1>cl : Command line error D8045 : cannot compile C file '..\src\zlib-1.2.5\zutil.c' with the /clr option

You could change it to cpp to get it compiled by the C++ compiler (and fix any compile errors that introduces). 您可以将其更改为cpp以使其由C ++编译器编译(并修复引入的任何编译错误)。 That may be more difficult than just using a shared library (dll). 这可能比仅使用共享库(dll)更困难。

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

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