digitalmars.D - Is it possible to wrap c++ functions to use with D (i.e. the Qt gui)?
- Kramer (9/9) Feb 21 2005 Trolltech - the company that produces the Qt gui environ. - will be rele...
- Joshua Cearley (10/23) Feb 21 2005 This is something I've been looking in to for my D Interface Generator
- remy.moueza free.fr (15/24) Feb 22 2005 Indeed, this is the only way, IMO. But it works very well: I've written ...
- Russ Lewis (2/32) Feb 25 2005
- nail (7/12) Feb 22 2005 Even if D would easily support C++ wraping, using Qt not became trivial....
- Carlos Santander B. (7/22) Feb 22 2005 DMD accepts extern(C++), but it's non-portable even using DMD, because
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
Feb 21 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++? :( -KramerThis 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
Feb 21 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. -JCIndeed, 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.
Feb 22 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. -JCIndeed, 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.
Feb 25 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.htmlEven 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
Feb 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++? :( -KramerDMD 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
Feb 22 2005