如何将 C# 转换为 C++

发布于 2024-10-11 00:41:53 字数 1704 浏览 9 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

↙温凉少女 2024-10-18 00:41:53

实际上,由于在unix上混合C#和C++很复杂,我正在尝试将C#转换为C++

你考虑过 Mono ?在开始学习 C++ 以便在 Unix 上转换和运行现有的 .NET 应用程序之前,这绝对值得检查。它也是二进制兼容的,这意味着您甚至不需要重新编译现有的程序集。

Actually as it is complicated to mix C# and C++ on unix, I am trying to convert C# to C++

Have you considered Mono? It is something that's definitely worth checking before starting to learn C++ in order convert and run an existing .NET application on Unix. It's also binary compatible meaning that you don't even need to recompile your existing assembly.

凉城凉梦凉人心 2024-10-18 00:41:53

学C#,学C++,花大量时间重写。

或者使用 C# 程序集中的 PInvoke 调用 C++ dll。

或者编写托管 C++ 并使用 /clr 开关进行编译。生成的程序集可以从 C# 项目中引用和使用。

Learn C#, learn C++, and spend a lot of time rewriting.

Or use PInvoke from the C# assembly to call into a C++ dll.

Or write managed C++ and compile with the /clr switch. The resulting assembly can be referenced and used from C# projects.

最笨的告白 2024-10-18 00:41:53

将 C# 直接转换为 C++ 以使其在 Unix 机器上运行几乎是不可能的。

这主要是由于 .NET Framework(来自 C++)在 Unix 计算机上不可用。 Mono 将允许您运行许多 C#/.NET 程序,但不支持 C++/CLI(允许直接使用 .NET Framework 的 C++ 扩展)。

转换语言是可能的 - 尽管由于方法的差异(例如,C# 中的垃圾收集)而很困难,但框架调用将需要移植到不同的库,并且通常不是直接转换的良好候选者。

例如,在上面的代码中,您必须决定使用 C++ 库进行 Web 访问 - 一旦做出选择,它将决定调用该库以下载网站字符串所需的代码。

It is nearly impossible to directly translate C# to C++ so that it will run on Unix machines.

This is mainly due to the fact that the .NET Framework is not available (from C++) on Unix machines. Mono will allow you to run many C#/.NET programs, but does not support C++/CLI (the C++ extensions that allow directly working with the .NET Framework).

Converting the language is possible - though difficult due to differences in approach (e.g., garbage collection in C#), but the framework calls will require porting to different libraries, and it is often not a good candidate for a direct translation.

For example, in your code above, you'd have to decide on a C++ library for web access - and once you had that choice made, it would dictate the code required to call into that library to download the website string.

酷炫老祖宗 2024-10-18 00:41:53

我有时会使用 C# 到 C++ 转换器。它非常适合从 C# 到 C++ 或 C++/cli 的代码片段转换。

I'm using C# to C++ converter time to time. It's really great for snippet conversion from c# to c++ or c++/cli.

月亮邮递员 2024-10-18 00:41:53

考虑看看瓦拉。 Vala 是一种类似 C# 的语言,可以转换为 C,然后转换为可执行文件。与 C# 的差异很小。但你仍然需要使用你的大脑。

Consider looking at Vala. Vala is a C#-like language that converts into C and then into an executable. There are very little differences with C#. You will still have to use your brain though.

写下不归期 2024-10-18 00:41:53

您可能需要考虑 CoreRT。它是一个 .NET 项目,其目标是消除运行应用程序时目标平台上存在 CLR 的需要。相反,它从给定的 C# 代码生成 C++ 代码。该 C++ 代码可以在任何支持 C++ 的目标平台上进行编译和链接。

微软博客上的一篇文章称:“如果我真的想编写一些 C# 代码并让它在新的 IoT 设备上‘正常工作’,那么在 RyuJIT 能够生成与 IoT 设备兼容的机器代码之前,我别无选择。那个处理器和操作系统。”通过将 C# 交叉编译为 C++,.Net 开发人员可以交付他们的应用程序,而无需等待 .Net 在给定平台上部署。

https://github.com/dotnet/corert

You may want to consider CoreRT. It's a .NET project whose goal is to eliminate the need for the CLR to be present on the target platform for running an application. Instead, it generates C++ code from a given C# code. That C++ code is compiled and linked on any target platform that supports C++.

A post on a Microsoft blog said: "If I really want to write some C# code and have it 'just work' on a new IoT device, I don’t have any options until the RyuJIT is capable of generating machine code that works with that processor and operating system." By cross-compiling C# to C++, .Net developers can then deliver their applications without needing to wait for .Net to be deployed on a given platform.

https://github.com/dotnet/corert

挽袖吟 2024-10-18 00:41:53

编辑:
列出的网站已停止使用。我将把旧答案留在这里供参考......

旧答案:
这是一个在线转换器,可以为您自动化该过程! ...

Varycode 在线转换器

它可以进行 C# 到 C++ 的转换,以及转换器Ruby、Python、Java 和VB,显然!

编辑:
它似乎已经删除了 C++(和 java)功能 - 它说是暂时的,但现在已经这样做了很长一段时间。希望他们很快就能复活!
仍然适用于其他一些语言(VB、Ruby、Python、Boo)。

Edit:
The site listed has been discontinued. I'll leave the old answer here for reference ...

Old answer:
Here is an online converter that will automate the process for you! ...

Varycode online converter

It can do C# to C++ and back again as well as converters for Ruby, Python, Java & VB, apparently!

Edit:
It appears to have had its C++ (and java) functionality removed - it says temporarily, but has done so for a long time now. Hopefully they'll resurrect it soon!
Still works for some other languages (VB, Ruby, Python, Boo).

花想c 2024-10-18 00:41:53

正如这里已经提到的,库的翻译可能是一个问题,但在某些情况下可能会有所帮助的一个开源项目是:

http://alexalbala.github.io/Alter-Native/

其主页引用:

它提供了一个方便端口应用的工具
从 .NET 等高级语言到
本地语言,如 C++。这是一个研究项目
它正在开发中
UPC - 巴塞罗那科技大学与 AlterAid SL 的合作

As already mentioned here, the translation of libraries can be an issue, but one open source project that might help at some cases is:

http://alexalbala.github.io/Alter-Native/

Citation from its main page:

It provides a tool to easy port applications
from high-level languages such as .NET to
native languages like C++. It is a research project
and it is under development with the
collaboration of UPC - BarcelonaTech and AlterAid S.L.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文