如何通过 DLL 公开 erl_interface(Erlang 的 C 库)?
过去三天我一直在不间断地研究 Erlang 的完全托管界面。此时,我决定必须有一种更简单的方法。我已经有 3000 多行了,但它甚至还没有处于可编译状态。老实说,我迷失在自己的代码中。
于是,我想起了 Erlang 有一个名为 erl_interface 的 C 库。不幸的是,它仅以 .LIB 文件形式提供,无法通过 P/Invoke 使用。我现在正在研究通过 DLL 公开静态库的方法。
我想远离 Visual C++,主要是因为我本质上不是 C/C++ 程序员,而且我发现它真的很难配置。在处理 C 语言中的任何内容时,TinyC 是我选择的编译器。
我该如何解决这个问题?
我知道我可以将 erl_interface 链接到 DLL,但如何公开这些函数?我是否必须将它们中的每一个都包装在我自己的导出中?这可能不会成为问题,因为我可以编写一个脚本来从头文件生成代码。但有没有一种我不知道的更简单的方法?
另外,请不要推荐 OTP.NET。这是一个不错的库,但我希望使用它,这是一个大型项目,所以我想将其保留在内部。
I've been working non-stop for the last three days on a completely managed interface to Erlang. At this point, I've decided that there simply must be an easier way. I've got a little over 3000 lines and it's not even in a compilable state yet. To be honest, I'm getting lost in my own code.
So, I then remembered that Erlang has a C library called erl_interface. Unfortunately, it only comes as a .LIB file, which isn't usable via P/Invoke. I'm now investigating ways to expose the static library through a DLL.
I'd like to stay away from Visual C++, mostly because I'm not a C/C++ programmer by nature and I find it really difficult to configure. TinyC is my compiler of choice when working with anything in C.
How can I go about this?
I know I can link erl_interface to a DLL, but how can I expose the functions? Do I have to essentially wrap each and every one of them in my own exports? That probably won't be a problem, since I could write a script to generate the code from the header file. But is there an easier way that I just don't know about?
Also, please don't recommend OTP.NET. It's a nice library, but I'm looking to use this is a large project, so I'd like to keep it in-house.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,您的问题是将静态库转变为动态库之一。
最省力的解决方案是用“C”编写一个薄的填充文件,该文件仅委托给 .lib 中的文件,例如
并从该文件和静态库构建一个 DLL。
事后思考——您可以采取另一种方法——即将 .lib 构建到 C++/CLI 程序集中,并在其中进行转换/包装。毕竟,这就是 C++/CLi 的用途。
So, your problem is one of turning a static lib into a dynamic one.
The least-effort solution would be to write a thin shim file in 'C', that just delegates to the files in the .lib e.g.
and build a DLL from that and the static lib.
Afterthought -- There is another approach you could take -- which is build the .lib into a C++/CLI assembly and do the transition/wrapping in that. It's what C++/CLi is there for, after all.
如果您需要有关使用 C 连接 Erlang 的帮助,请查看“EPAPI”(Erlang 端口 API)链接文本。您当然可以浏览源代码,因为它托管在 Google Code 上。 DEBIAN 存储库也可用。
If you want some help with interfacing to Erlang with C, have a look at "EPAPI" (Erlang Port API) link text. You can of course browse the source code since it is hosted on Google Code. A DEBIAN repository is also available.