View previous topic :: View next topic |
Author |
Message |
Norfenstein
Joined: 28 Jul 2004 Posts: 2
|
Posted: Wed Jul 28, 2004 1:18 pm Post subject: Linking with SDL |
|
|
This might be a newbie-ish problem, but I haven't had any success getting SDL to work with D. I got the compiler working fine, everything in the default locations (on Windows XP) and unzipped the SDL file on DedicateD to c:\d\sdl. I thought the following would work to compile the included test files (after changing string and c.stdio to std.string and std.c.stdio in the import section):
C:\d\sdl\test>dmd testbitmap.d picture.d -g -d -I..\
But I got a string of errors like this:
testbitmap.obj(testbitmap)
Error 42: Symbol Undefined _SDL_CreateRGBSurface
Related to all the SDL functions used in the program, followed by:
--- errorlevel 10
Adding the switch "-L..\" got me the following error above the rest:
OPTLINK : Warning 9: Unknown Option : NOI..\
And using "-c" got me no errors but an unworking exe, so I assume the problem is me not knowing how to properly use/link lib files. Any help would be greatly appreciated. |
|
Back to top |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Wed Jul 28, 2004 5:23 pm Post subject: Re: Linking with SDL |
|
|
Norfenstein wrote: | This might be a newbie-ish problem, but I haven't had any success getting SDL to work with D. I got the compiler working fine, everything in the default locations (on Windows XP) and unzipped the SDL file on DedicateD to c:\d\sdl. | As old as that code is I'd say you're lucky to get it to compile. I think there are several newer versions floating around. I don't know how much better it is, but you might want to look at s31552's web page.
Norfenstein wrote: | I thought the following would work to compile the included test files (after changing string and c.stdio to std.string and std.c.stdio in the import section):
C:\d\sdl\test>dmd testbitmap.d picture.d -g -d -I..\
But I got a string of errors like this:
testbitmap.obj(testbitmap)
Error 42: Symbol Undefined _SDL_CreateRGBSurface | This is a linking error (which means the compile phase was successful). It sounds like you need to add a .lib to the compile path, such as: Code: | dmd testbitmap.d picture.d sdl.lib |
Norfenstein wrote: | ...
And using "-c" got me no errors but an unworking exe, so I assume the problem is me not knowing how to properly use/link lib files. | That's right.
Hopefully, the SDL.lib in the DedicateD archive will work for you. Otherwise, you might need to create your own .lib as I discussed with someone working with OpenGL recently. |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Thu Jul 29, 2004 12:17 am Post subject: |
|
|
Take a look at my project 'Derelict' here on dsource. It was created to make it easier to use SDL and others, and you don't need to worry about SDL.lib. The dll is loaded explicitly, so you can catch an exception and fail gracefully if it is missing from the user's machine.
Derelict has an up-to-date (and working) SDL binding (along with OpenGL, GLU and an in-progress Python binding). From the Derelict download section, you can pickup Derelict-0.1, but if all you want is SDL you might just want to pull it directly from the svn repository (I recommend that anyway, as there have been some changes since I packaged the download).
Be sure to read the readme. If you are on Windows you won't need to do anything special, but if you are using Linux let me know and I'll tell you what needs to be done. |
|
Back to top |
|
|
Norfenstein
Joined: 28 Jul 2004 Posts: 2
|
Posted: Thu Jul 29, 2004 12:40 am Post subject: |
|
|
Thank you jcc7! Passing in the lib as you described made everything work properly. I was a little thrown off since the D compiler page at Digital Mars mentions a bunch of file types you can pass to the compiler but for some reason excludes .lib's, so I thought maybe they had to be passed to the linker with -L. Thankfully it's all much simpler.
Glad to say I also got OpenGL working with the files at D - Porting. The ones at DedicateD are too far out of date and wouldn't compile properly.
aldacron: I had briefly looked over Derelict while trying to solve this problem and decided I didn't want another layer to understand just yet. Looking briefly at it again, it seems like it could be valuable even after getting SDL and OpenGL to work, so I'll give it a go and see what it can do. |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Thu Jul 29, 2004 4:41 am Post subject: |
|
|
Norfenstein wrote: | I had briefly looked over Derelict while trying to solve this problem and decided I didn't want another layer to understand just yet. |
Derelict does not introduce another layer. In the abstract, it's no different than using the bindings from DedicateD. Technically, there's one minor differece. When using a Derelict package, you have to call a load function. Using the DerelictSDL package, for example, you would call:
DerelictSDL_Load();
This loads the dynamic library. You can wrap that in a try..catch block in case the library fails to load. That's the only difference. From that point on you can call SDL_* functions normally.
By implicitly linking to sdl.dll, as you do when using the DedicateD files, there's nothing you can do if the dll is missing. The user will get that nasty OS pop up message: "A required DLL..blahblahblah". Derelict gives you the ability to handle missing dlls at the application level, so you can do whatever you want on failure - write a log message, pop up a message box, fallback to a different API, direct the user to an error page on your website... whatever you need to do.
Derelict is just another option to the gazillion other bindings out there, and is particularly useful for those who don't want implicit linkage. Not many know about it though. |
|
Back to top |
|
|
|
|
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
|