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

时间:2021-03-24 18:51:59

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在Unix上构建在GCC上的代码。我想创建一个单独的可执行文件,它不依赖于我自己创建的任何dll,只构建在Windows操作系统的dll中。

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. (Perhaps this avoidance is even more complex?)

我看到一些建议将其拆分为一个单独的DLL,该DLL将链接到我的可执行文件中,但如果可能的话,我希望避免共享库的复杂性。(或许这种回避更复杂?)

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

1 个解决方案

#1


3  

You could change it to cpp to get it compiled by the C++ compiler (and fix any compile errors that introduces). That may be more difficult than just using a shared library (dll).

您可以将它更改为cpp,由c++编译器编译(并修复引入的任何编译错误)。这可能比仅仅使用共享库(dll)更困难。

#1


3  

You could change it to cpp to get it compiled by the C++ compiler (and fix any compile errors that introduces). That may be more difficult than just using a shared library (dll).

您可以将它更改为cpp,由c++编译器编译(并修复引入的任何编译错误)。这可能比仅仅使用共享库(dll)更困难。