Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
The community reviewed whether to reopen this question 3 years ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
你考虑过 Mono ?在开始学习 C++ 以便在 Unix 上转换和运行现有的 .NET 应用程序之前,这绝对值得检查。它也是二进制兼容的,这意味着您甚至不需要重新编译现有的程序集。
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.
学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.
将 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.
我有时会使用 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.
考虑看看瓦拉。 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.
您可能需要考虑 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
编辑:
列出的网站已停止使用。我将把旧答案留在这里供参考......
旧答案:
这是一个在线转换器,可以为您自动化该过程! ...
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).
正如这里已经提到的,库的翻译可能是一个问题,但在某些情况下可能会有所帮助的一个开源项目是:
http://alexalbala.github.io/Alter-Native/
其主页引用:
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: