FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to interface with C?

 
Post new topic   Reply to topic     Forum Index -> General
View previous topic :: View next topic  
Author Message
CrypticMetaphor88



Joined: 07 Dec 2010
Posts: 4

PostPosted: Thu Dec 09, 2010 6:06 am    Post subject: How to interface with C? Reply with quote

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
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Thu Dec 09, 2010 11:34 am    Post subject: Reply with quote

Have a look at http://dsource.org/projects/derelict/ it has bindings for SDL and various other game/media related libraries.
Back to top
View user's profile Send private message
CrypticMetaphor88



Joined: 07 Dec 2010
Posts: 4

PostPosted: Thu Dec 09, 2010 11:48 am    Post subject: Reply with quote

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
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sat Dec 11, 2010 8:59 am    Post subject: Reply with quote

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
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Sat Dec 11, 2010 9:31 am    Post subject: Re: How to interface with C? Reply with quote

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
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group