View previous topic :: View next topic |
Author |
Message |
CrypticMetaphor88
Joined: 07 Dec 2010 Posts: 4
|
Posted: Thu Dec 09, 2010 6:06 am Post subject: How to interface with C? |
|
|
I've searched for it in a lot of places, created the d include files, used htod, some other things as well, but I always seem to get errors of some kind. It would be too numerous to no go trough the list of all the things I've tried.
I'm probably missing something obvious, and many of you probably already have used libraries written in C, so I'll just ask the following:
What would I have to do to compile a d program that uses the SDL library to load a simple window? And maybe write "hello" on the canvas or whatever.
sdl library can be found here:
http://www.libsdl.org/download-1.2.php |
|
Back to top |
|
|
doob
Joined: 06 Jan 2007 Posts: 367
|
|
Back to top |
|
|
CrypticMetaphor88
Joined: 07 Dec 2010 Posts: 4
|
Posted: Thu Dec 09, 2010 11:48 am Post subject: |
|
|
I tried that already, doesn't work. I'm using D2 so had to download derelict2 (d1 doesn't work), and I get some kind of linking errors with derelict2 but I think that is because I'm doing something wrong there.
But that's not the point, what I'm trying to say is that I want to be able to make a simple SDL program with D without relying on other libraries, I want to understand how it works.
You know the proverb:
"Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime." |
|
Back to top |
|
|
doob
Joined: 06 Jan 2007 Posts: 367
|
Posted: Sat Dec 11, 2010 8:59 am Post subject: |
|
|
If you want to everything yourself then you have to create bindings to the functions in SDL you want to use. What that means is you have to translate the SDL header files to D. Have a look at: http://www.digitalmars.com/d/1.0/htomodule.html and http://www.digitalmars.com/d/1.0/interfaceToC.html . Then you just need to link to the SDL library. Derelict links dynamically with its libraries instead of statically and it's using function pointers instead of function declarations. |
|
Back to top |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Sat Dec 11, 2010 9:31 am Post subject: Re: How to interface with C? |
|
|
CrypticMetaphor88 wrote: | What would I have to do to compile a d program that uses the SDL library to load a simple window? And maybe write "hello" on the canvas or whatever. | I don't really know anything about SDL, but I do know that the Derelict project is one of the oldest D projects that is still maintained. If you run into problems getting it to work, just ask a question in the Derelict forum.
Also, I found this page in the "binding" project: Simple Direct Media Layer. I don't know if it was ever that useful, and now it probably suffers from bitrot. I'm sure that it's written for D1 (or pre-D1), but it could be easy to adapt for D2. And I think that whoever created it disappeared a few years ago.
I still think that using Derelict is your best bet. Good luck! |
|
Back to top |
|
|
|