如何使用由D C库? [英] How to use a C library from D?

查看:109
本文介绍了如何使用由D C库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我听到了D编程,它是为C code兼容。不过我还没有发现它是否可以使用C库像由D GTK或PortAudio的信息吗?
如果可能的话,你能解释一下如何做到这一点?

Today I heard about the D programming and that it is compatible to C code. Nevertheless I haven't found any information on whether it is possible to use C libraries like GTK or PortAudio from D? If it is possible, could you explain how to do this?

推荐答案

这是可以调用从D C库,你需要做的是C头文件转换为D.在大多数情况下,这是pretty简单,有一个很难使用的命令行工具帮助自动化过程。它从来没有真正为我工作的任何东西,但玩具的例子,但它可能是一个好的开始看到那种需要进行转换。只要把你遇到麻烦翻译片段成本身就是一个头,看看htod做它。

It is possible to call C libraries from D. What you need to do is to convert the C header files to D. For the most part this is pretty straightforward, and there is a hard-to-use command-line tool to help automate the process. It's never really worked for me on anything but toy examples, but it could be a good start to see the kind of transformations that need to be done. Just put a snippet you're having trouble translating into a header by itself and see what htod does with it.

您通常会遇到的最大问题是创造性的使用了C preprocessor的。有些东西可以变成版本()语句D​​,但不是全部。

The biggest problem you'll usually encounter is creative use of the C preprocessor. Some things can be turned into version() statements in D, but not all.

至于实际编制,并与code连接,在类Unix平台我认为你可以编译和使用GCC的C code链接。在Windows上,你要么编译使用DMC和链路与DMD的C文件。或者你可以编译C code使用任意编译器,可这一点,然后用DMD链接,你需要做一个DMD兼容导入库出来的DLL的DLL。这可以使用在免费基本工具包中的IMPLIB工具从DigitalMars来完成。

As for actually compiling and linking with the code, on unix-like platforms I think you can compile and link in the C code using GCC. On Windows you either have to compile the C files using DMC and link with DMD. Or you can compile the C code into a DLL using any compiler capable of that, and then to link with DMD you need to make a DMD-compatible import lib out of the DLL. This can be done using the implib tool found in the free Basic Utilities Package available from DigitalMars.

还有很多这些头翻译已经完成。它先浏览绑定项目d源的,或要求在digitalmarsð新闻组首先着手的东西大如翻译GTK头前是非常有用的。很多流行的库,例如GTK已经被包裹(例如在这里: GTKD

There are also a lot of these header translations have already been done. It's useful to browse the Bindings project of Dsource first, or ask on the digitalmars D newsgroups first before embarking on something big like translating GTK headers. A lot of popular libraries like GTK have already been wrapped (e.g. here: GTKD)

这篇关于如何使用由D C库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆