Jump to page: 1 24  
Page
Thread overview
How to use D for cross platform development?
Mar 25, 2012
Bennie Copeland
Mar 25, 2012
maarten van damme
Mar 25, 2012
Iain Buclaw
Mar 25, 2012
Jacob Carlborg
Mar 25, 2012
Jacob Carlborg
Mar 25, 2012
Iain Buclaw
Mar 25, 2012
James Miller
Mar 25, 2012
Iain Buclaw
Mar 28, 2012
Bennie Copeland
Mar 28, 2012
Jacob Carlborg
Mar 28, 2012
Nick Sabalausky
Mar 28, 2012
H. S. Teoh
Mar 28, 2012
Nick Sabalausky
Mar 26, 2012
Michel Fortin
Mar 25, 2012
Jonathan M Davis
Mar 25, 2012
Kevin Cox
Mar 26, 2012
Chris W.
Mar 28, 2012
Bennie Copeland
Mar 28, 2012
Iain Buclaw
Mar 28, 2012
Nick Sabalausky
Mar 29, 2012
Chris W.
Mar 29, 2012
Jacob Carlborg
Mar 29, 2012
Chris W.
Mar 29, 2012
Jacob Carlborg
Mar 29, 2012
Bennie Copeland
Mar 29, 2012
Gour
Mar 30, 2012
Jacob Carlborg
Mar 30, 2012
Chris W.
Mar 30, 2012
Jacob Carlborg
Mar 30, 2012
Michel Fortin
Mar 30, 2012
Jacob Carlborg
Mar 30, 2012
Michel Fortin
March 25, 2012
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.

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.

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?
March 25, 2012
Op 25 maart 2012 13:12 schreef Bennie Copeland <mugen.kanosei@gmail.com>het volgende:

> 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.


>From what I've heard this was a certain bug  (
http://d.puremagic.com/issues/show_bug.cgi?id=4583) that made it impossible
to generate position independent code and thus no shared objects. This bug
was fixed in dmd version 2.057 so it should work with dmd -c -fPIC and then
use gcc on your platform to create the shared object.
If you don't need/want to use dmd I think gdc is capable of doing it.

Maarten


March 25, 2012
On 25 March 2012 13:22, maarten van damme <maartenvd1994@gmail.com> wrote:
> Op 25 maart 2012 13:12 schreef Bennie Copeland <mugen.kanosei@gmail.com> het volgende:
>
>> 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.
>
>
> From what I've heard this was a certain bug
>  (http://d.puremagic.com/issues/show_bug.cgi?id=4583) that made it
> impossible to generate position independent code and thus no shared objects.
> This bug was fixed in dmd version 2.057 so it should work with dmd -c -fPIC
> and then use gcc on your platform to create the shared object.
> If you don't need/want to use dmd I think gdc is capable of doing it.


The rule of thumb generally is if you are able to build a gcc C cross compiler, you can just tack gdc onto it and it will be fine.


Regards

-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';
March 25, 2012
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.

> 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/

-- 
/Jacob Carlborg
March 25, 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
March 25, 2012
On 2012-03-25 18:20, Alex Rønne Petersen wrote:

> 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.

Ok, I didn't know about that. Is GDC using its own runtime?

-- 
/Jacob Carlborg
March 25, 2012
On 25 March 2012 21:31, Jacob Carlborg <doob@me.com> wrote:
> On 2012-03-25 18:20, Alex Rønne Petersen wrote:
>
>> 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.
>
>
> Ok, I didn't know about that. Is GDC using its own runtime?
>
> --
> /Jacob Carlborg

A spork of druntime, yes.

-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';
March 25, 2012
On 26 March 2012 09:44, Iain Buclaw <ibuclaw@ubuntu.com> wrote:
> A spork of druntime, yes.

A spork? I've never heard that before...

--
James Miller
March 25, 2012
On 25 March 2012 21:55, James Miller <james@aatch.net> wrote:
> On 26 March 2012 09:44, Iain Buclaw <ibuclaw@ubuntu.com> wrote:
>> A spork of druntime, yes.
>
> A spork? I've never heard that before...
>

It's constantly merged from upstream, however we keep any GDC-specific differences in-house.

-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';
March 25, 2012
On Monday, March 26, 2012 09:55:00 James Miller wrote:
> On 26 March 2012 09:44, Iain Buclaw <ibuclaw@ubuntu.com> wrote:
> > A spork of druntime, yes.
> 
> A spork? I've never heard that before...

http://en.wikipedia.org/wiki/Spork

Not that it has anything to do with software...

- Jonathan M Davis
« First   ‹ Prev
1 2 3 4