How to use D for cross platform development?

Alex Rønne Petersen xtzgzorex at gmail.com
Sun Mar 25 09:20:50 PDT 2012


On 25-03-2012 17:04, Jacob Carlborg wrote:
> On 2012-03-25 13:12, Bennie Copeland wrote:
>> Hello all. I'm sorry if this has been addressed before.
>>
>> For a little background. I've been studying C++ with the intention of
>> doing cross platform work on Windows, OSX, and eventually iOS and some
>> other mobile OSes. My plan was to write cross platform shared libraries
>> for the core functionality and implement the GUI using Win32, Cocoa,
>> etc. Well, while C++ is powerful, I'm finding it a beast to work with. I
>> kept thinking about abandoning C++ altogether and using C# with Mono
>> until I stumbled upon D. D sounds exactly like what I am looking for,
>> powerful yet productive and native.
>
> First I have to say that D is a great language for doing cross platform
> development.
>
> But for iOS there are a couple of big problems. The reference D
> compiler, DMD, does not have an ARM-backend. There are other compilers
> available though: LDC, the DMD frontend on the LLVM backend and GDC, the
> DMD frontend on the GCC backend. Second big problem is the D runtime
> does not support ARM. As far as I know, no one has ever used D on iOS.

About ARM support: That's not strictly true. D on ARM should work fine 
at this point in time if you build druntime/phobos in GDC with 
-fno-section-anchors (there is even some experimental Android support). 
But indeed, no iOS support.

>
>> My question however is how to do D cross platform development. I can't
>> seem to find any recent information about it. From what I have gathered
>> so far it seems, shared libraries are possible on win/osx/linux, but
>> only when linked against other D code. For linking against C, I can
>> create a DLL in windows, but I can't create an .so in linux, and no
>> information at all about OSX. Some of the information I found is years
>> old and I can't tell if the situation has changed. There is nothing in
>> the FAQ about libraries. And googling provides little information.
>
> You should be able to create shared libraries for linking with C code.
> You just need to make sure you initialize the D runtime. I'm not
> entirely sure about the status for creating shared libraries, not sure
> if the runtime has been modified to support that on all platforms. I
> think Windows and Linux is good to go but I don't think the runtime is
> not ready yet for Mac OS X.
>
>> So, is it possible to write the core of an application in a cross
>> platform D library that can be callable by C, C++, or Objective-C to
>> provide the GUI elements?
>> If not, is it possible to write a C wrapper around the library that is
>> then callable by C, C++ or Objective-C?
>> How have others approached this situation?
>> Besides the library issues, what other issues or gotchas should I look
>> out for in regards to cross platform development?
>
> When it comes to providing a GUI for your application there are a couple
> of choices:
>
> * Directly access the native GUI operations of the operating system
> * Use a cross platform GUI library
>
> For directly accessing the native GUI of the operating system there are
> again various options.
>
> First option, C wrapper. A C wrapper works for all languages you need to
> interact with: C, C++ and Objective-C.
>
> D has limited support for interfacing directly with C++. For example, D
> understand the C++ mangling and you can call virtual C++ functions from
> D. This could be another idea, or used together with C wrappers.
>
> http://dlang.org/cpp_interface.html
>
> For interfacing with Objective-C there are a couple of options as well.
> One option is to use C wrappers. Another is to use the Objective-C
> runtime functions to get be able to create Objective-C class and methods
> from D. There are two projects that have gone this road and created a
> fully working, fully automatic bridge between D and Objective-C.
> Although it turned out to not be usable in practice.
>
> A third option for Objective-C would be to use a fork of DMD that makes
> it possible to directly interface with Objective-C, just as it's
> possible with C. I'm not sure of the status of this project but an alpha
> has been released.
>
> D/Objective-C bridge: http://dsource.org/projects/dstep
> D/Objective-C bridge: http://michelf.com/projects/d-objc-bridge/
> DMD fork: http://michelf.com/projects/d-objc/
>
>
>
> Cross platform GUI libraries. Here are again several options:
>
> * DWT - Port of SWT. Uses the native operations of the operating system.
> Supports Windows (win32) and Linux (GTK+). Support for Mac OS X (Cocoa)
> is worked on.
>
> http://dsource.org/projects/dwt
>
> * gtkD - Bindings to GTK. Does not use the native drawing operations of
> the operating system. Available on all platforms.
>
> http://dsource.org/projects/gtkd
>
> * QtD - Bindings to Qt. Use the native drawing operations of the
> operating system (I think). Available on all platforms. Not sure if this
> is developed any more.
>
> http://dsource.org/projects/qtd
>
> * wxD - Bindings to wxWidgets. Use the native drawing operations of the
> operating system. Available on all platforms. Not sure of the status.
>
> http://wxd.sourceforge.net/
>


-- 
- Alex


More information about the Digitalmars-d mailing list