英文:
Is there a way to wrap a Go library in .Net
问题
我在这里和那里看到过Go语言被称为现代版的C/C++(意思是:具有现代语法和内存管理,但速度大致相当)。
我有兴趣利用这种语言的力量,在我们的.Net应用程序中包含一个图像处理库。
但这就引出了将Go库封装在.Net外壳中的问题。我以前成功地使用C++/CLI封装了一个C库;是否有办法用类似的方式封装Go库?
我不想使用我之前尝试过的Swig,它非常糟糕,大部分时间都无法正常工作。
英文:
I have seen here and there that Go is like a modern-time C/C++ (meaning: with modern syntax and memory management, but about as fast).
I'm interested in leveraging the power of such a language, to include an image processing library in our .Net application.
But that raises the problem of wrapping the Go library in a .Net shell. I have successfully wrapped a C library using C++/CLI ; is there a way to do a similar thing with Go ?
I would like to NOT use Swig, which I tried before, and is absolutely awful and doesn't work most of the time.
答案1
得分: 4
目前无法将Go代码嵌入到主语言不是Go的程序中,因为Go需要一个复杂的运行时环境,与许多其他组件进行连接。唯一可能的方法是从Go程序中调用C函数,然后这些函数可以再调用Go函数。你可能需要设计一个解决方案,使用某种形式的进程间通信,将你想要用Go编写的部分运行在不同的进程中。
英文:
It is currently not possible to embed Go code into a program whose main language isn't Go because Go needs a non-trivial runtime that hooks into many things. The only possible thing is to call C functions from a Go program; these functions may then in turn call Go functions. You might want to design a solution that uses some sort of inter-process communication instead where the part you want to write in Go runs in a different process.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论