[英]What is the best way to port a C++ library to C#?
I have a (header only) C++ library that I am looking to port to C#.我有一个(仅标头)C++ 库,我希望将其移植到 C#。 It is a wrapper of the win api which I have made for a certain purpose.它是我为特定目的制作的 win api 的包装器。 I want to port it to C# because I want to develop it further using C#.我想将它移植到 C#,因为我想使用 C# 进一步开发它。 What is the most efficient (and easiest?) way to port it.移植它的最有效(也是最简单的?)方法是什么。 Please note that I do not want something hectic because I don't want to spend more time porting the library than it took to make that library in the first place.请注意,我不想要忙碌的事情,因为我不想花更多的时间来移植库而不是最初制作该库所花费的时间。 So is there a way?那么有没有办法呢?
It depends very much on how big your lib is, how it is structured, how your memory allocation looks like, how much you made use of libs not available in C# (like the C++ std lib), how much C++ template programming you have used etc.这在很大程度上取决于你的 lib 有多大、它的结构如何、你的内存分配是什么样的、你使用了多少 C# 中不可用的 lib(如 C++ std lib)、你使用了多少 C++ 模板编程等等。
Different strategies may be可能有不同的策略
"Header only" does not seem to make a real difference. “仅标题”似乎没有真正的区别。 In fact, things may technically get a little bit easier when you have just one C++ file for each class to be ported to one C# class file.事实上,当您将每个类的一个 C++ 文件移植到一个 C# 类文件时,从技术上讲,事情可能会变得容易一些。
A couple of ways I can think of.我能想到的几种方法。
Since you already have c++ library that you can fully control, I would try to go with #2 first.由于您已经拥有可以完全控制的 C++ 库,因此我会先尝试使用 #2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.