| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
September 21, 2015 can D compiler support C/C++ source code? | ||||
|---|---|---|---|---|
| ||||
While D is binary compatible with C code, it cannot compile C code nor C header files. In order to use C/C++ binary libs, I have to convert C or C++ header files to D module. It make very difficult to use C binary libs. Can D compiler support C/C++ source code in future? If can, it will become easy and convenient to use C/C++ libs in Dlang. Hope to achieve it as soon as possible! | ||||
September 21, 2015 Re: can D compiler support C/C++ source code? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to donglei | On 21/09/15 5:24 PM, donglei wrote:
> While D is binary compatible with C code, it cannot compile C code nor C
> header files.
> In order to use C/C++ binary libs, I have to convert C or C++ header
> files to D module.
> It make very difficult to use C binary libs.
> Can D compiler support C/C++ source code in future?
> If can, it will become easy and convenient to use C/C++ libs in Dlang.
> Hope to achieve it as soon as possible!
What you are asking for is a c/c++ frontend as part of the D compiler, which is completely infeasible. There are attempts such as Calypso to use an existing c++ front end to generate D bindings. But even they have a hard time, especially with STL.
This is not going to happen. You will need to create bindings some way or another. They are easy and simple to do.
| |||
September 21, 2015 Re: can D compiler support C/C++ source code? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to donglei | On Monday, 21 September 2015 at 05:25:01 UTC, donglei wrote: > While D is binary compatible with C code, it cannot compile C code nor C header files. > In order to use C/C++ binary libs, I have to convert C or C++ header files to D module. > It make very difficult to use C binary libs. > Can D compiler support C/C++ source code in future? > If can, it will become easy and convenient to use C/C++ libs in Dlang. > Hope to achieve it as soon as possible! unfortunately no... as stated at http://dlang.org/cpp_interface.html to support C/C++ source would be practically unimplementable note I say practically because while theoretically it is possible, the D community has neither the resources nor the time to implement such a feature. If you look around D.announce I seem to remember someone hacked up LLVM and clang to allow such interface. | |||
September 21, 2015 Re: can D compiler support C/C++ source code? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to donglei | On 2015-09-21 07:24, donglei wrote: > While D is binary compatible with C code, it cannot compile C code nor C > header files. > In order to use C/C++ binary libs, I have to convert C or C++ header > files to D module. > It make very difficult to use C binary libs. > Can D compiler support C/C++ source code in future? > If can, it will become easy and convenient to use C/C++ libs in Dlang. > Hope to achieve it as soon as possible! For C, there's a tool called DStep [1] that can automatically generate bindings. It's not 100% perfect but will get you a long way. [1] https://github.com/jacob-carlborg/dstep -- /Jacob Carlborg | |||
September 21, 2015 Re: can D compiler support C/C++ source code? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to donglei | On Monday, 21 September 2015 at 05:25:01 UTC, donglei wrote: > While D is binary compatible with C code, it cannot compile C code nor C header files. > In order to use C/C++ binary libs, I have to convert C or C++ header files to D module. > It make very difficult to use C binary libs. > Can D compiler support C/C++ source code in future? > If can, it will become easy and convenient to use C/C++ libs in Dlang. > Hope to achieve it as soon as possible! There is https://github.com/Syniurge/Calypso | |||
September 21, 2015 Re: can D compiler support C/C++ source code? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | On Monday, 21 September 2015 at 05:32:52 UTC, Rikki Cattermole wrote:
> What you are asking for is a c/c++ frontend as part of the D compiler, which is completely infeasible.
Making a c frontend part of the compiler should be feasible. I can think of several distinct approaches.
| |||
September 21, 2015 Re: can D compiler support C/C++ source code? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | On Monday, 21 September 2015 at 05:32:52 UTC, Rikki Cattermole wrote:
> What you are asking for is a c/c++ frontend as part of the D compiler, which is completely infeasible.
Of course it's feasible, but it would mean that the D compiler would have to have a full-blown C++ compiler built into it, and we don't want that maintenance nightmare, and we certainly don't want to put in the time and effort that would be required to do it. D already has far better support for C/C++ than is typical of languages which aren't C or C++, and it may improve further, but there are limits to what is reasonable to do, and it's been stated on multiple occasions that we don't want to implement C/C++ in the D compiler.
- Jonathan M Davis
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply