Thread overview
Is it possible to wrap c++ functions to use with D (i.e. the Qt gui)?
Feb 22, 2005
Kramer
Feb 22, 2005
Joshua Cearley
Feb 22, 2005
remy.moueza
Feb 25, 2005
Russ Lewis
Feb 22, 2005
nail
February 22, 2005
Trolltech - the company that produces the Qt gui environ. - will be releasing a GPL Windows version of their software in Q2 2005: http://www.trolltech.com/developer/faqs/duallicense.html#q113

I'd like to use this gui but, according to the doc, D does not interface with c++: http://www.digitalmars.com/d/interface.html

So, is there any way to wrap c++ functions so they can be used in D?

I understand that you can directly access a C function by using the extern (C)
linkage declaration, but there's nothing for c++? :(

-Kramer


February 22, 2005
Kramer wrote:

> Trolltech - the company that produces the Qt gui environ. - will be releasing a GPL Windows version of their software in Q2 2005: http://www.trolltech.com/developer/faqs/duallicense.html#q113
> 
> I'd like to use this gui but, according to the doc, D does not interface with c++: http://www.digitalmars.com/d/interface.html
> 
> So, is there any way to wrap c++ functions so they can be used in D?
> 
> I understand that you can directly access a C function by using the extern
> (C) linkage declaration, but there's nothing for c++? :(
> 
> -Kramer

This is something I've been looking in to for my D Interface Generator project (using C++ libs in D). AFAIK, to create the interface you need to write a C++ library that wraps around the lib you want to use. This new library cannot be object-oriented, so you program like C (things like CLASS_FUNCTION). Then you can export these functions with C linkage. You can import them back in D, and then write a wrapper around those to get the original class structure back. It sounds like a pain in the butt, but I think its the only way without C++ linkage or some fancy hacking.

-JC
February 22, 2005
>This is something I've been looking in to for my D Interface Generator project (using C++ libs in D). AFAIK, to create the interface you need to write a C++ library that wraps around the lib you want to use. This new library cannot be object-oriented, so you program like C (things like CLASS_FUNCTION). Then you can export these functions with C linkage. You can import them back in D, and then write a wrapper around those to get the original class structure back. It sounds like a pain in the butt, but I think its the only way without C++ linkage or some fancy hacking.
>
>-JC

Indeed, this is the only way, IMO. But it works very well: I've written a
generation tool in Python that uses gcc_xml output to generate C/C++ wrapping
code, D extern(C) importation and a D class hierarchy that mimic the C++ source.
I've first managed to compile and run the example given in the modified swig
version for D. Then I've used this tool to wrap the FLTK GUI toolkit. The
generated code was somewhat buggy but after a few correction I managed to make
it working. Currently I've only written and run a few samples with gdc-0.10 on
cygwin with FLTK 1.1.4.
As it's also a project for my current Engeener college year, I am mainly working
on a report and some documentation for the moment but I hope to make a release
soon.
I would have like to know if anyone had managed to compile FLTK with dmc or if
it is possible to use some bcc or Visual C++ ".lib" files, in order to test it
with the original dmd.

Remy.


February 22, 2005
In article <cveho1$1u09$1@digitaldaemon.com>, Kramer says...
>
>Trolltech - the company that produces the Qt gui environ. - will be releasing a GPL Windows version of their software in Q2 2005: http://www.trolltech.com/developer/faqs/duallicense.html#q113
>
>I'd like to use this gui but, according to the doc, D does not interface with c++: http://www.digitalmars.com/d/interface.html
>

Even if D would easily support C++ wraping, using Qt not became trivial. As I know Qt library obligies to use preprocessor named moc (for expanding constructions ala public signals: protected signals: emit, Q_OBJECT, etc, etc) wich, of course, oriented to use within c++ projects.

Victor Nakoryakov
nail-mail<at>mail<dot>com
February 22, 2005
Kramer wrote:
> Trolltech - the company that produces the Qt gui environ. - will be releasing a
> GPL Windows version of their software in Q2 2005:
> http://www.trolltech.com/developer/faqs/duallicense.html#q113
> 
> I'd like to use this gui but, according to the doc, D does not interface with
> c++: http://www.digitalmars.com/d/interface.html
> 
> So, is there any way to wrap c++ functions so they can be used in D?
> 
> I understand that you can directly access a C function by using the extern (C)
> linkage declaration, but there's nothing for c++? :(
> 
> -Kramer
> 
> 

DMD accepts extern(C++), but it's non-portable even using DMD, because it only works on Windows with DMC. Also, it only works with functions.

In conclussion, while I don't recommend it, maybe it can be useful in one or another project.

_______________________
Carlos Santander Bernal
February 25, 2005
Is this something you'd be willing to post?

remy.moueza@free.fr wrote:
>>This is something I've been looking in to for my D Interface Generator
>>project (using C++ libs in D). AFAIK, to create the interface you need to
>>write a C++ library that wraps around the lib you want to use. This new
>>library cannot be object-oriented, so you program like C (things like
>>CLASS_FUNCTION). Then you can export these functions with C linkage. You
>>can import them back in D, and then write a wrapper around those to get the
>>original class structure back. It sounds like a pain in the butt, but I
>>think its the only way without C++ linkage or some fancy hacking.
>>
>>-JC
> 
> 
> Indeed, this is the only way, IMO. But it works very well: I've written a
> generation tool in Python that uses gcc_xml output to generate C/C++ wrapping
> code, D extern(C) importation and a D class hierarchy that mimic the C++ source.
> I've first managed to compile and run the example given in the modified swig
> version for D. Then I've used this tool to wrap the FLTK GUI toolkit. The
> generated code was somewhat buggy but after a few correction I managed to make
> it working. Currently I've only written and run a few samples with gdc-0.10 on
> cygwin with FLTK 1.1.4. As it's also a project for my current Engeener college year, I am mainly working
> on a report and some documentation for the moment but I hope to make a release
> soon. I would have like to know if anyone had managed to compile FLTK with dmc or if
> it is possible to use some bcc or Visual C++ ".lib" files, in order to test it
> with the original dmd.
> 
> Remy.
> 
>