开发者

D and SDL - functions undefined

I've got this very simple D program (pk.d):

import std.stdio;
import SDL;

int main(string[] args) {
    writefln("Hello world");
    if (SDL_Init( SDL_INIT_VIDEO ) < 0) {
        writefln("Unable to init SDL");
        return 1;
    }

    return 0;
}

I've got a very straightforward make script (I'm on Windows here, but the Windows D compiler comes packaged with a bash interpreter):

DMD=dmd
DFLAGS=-I./l开发者_如何学Goib/SDL 

$(DMD) pk $(DFLAGS)
pk

But when I build it, I get Error 42: Symbol Undefined _SDL_Init

It managed to import SDL alright, and it finds SDL_INIT_VIDEO just fine. I went ahead and checked in SDL.d and found that there was a definition for SDL_Init: int SDL_Init(Uint32 flags);. I can't figure this out. This is the first non-STL library that I've imported with D, so hopefully my mistake is obvious, can anyone see it?


You also have to link with the SDL library. If you have one in the right format, simply pass it to the compiler along with your source files. Alternatively, you can add something like pragma(lib, "SDL.lib") to your program.


First of all you need also D bindings for SDL library.

import std.stdio;
import sdl;

int main(string[] args)
{
    SDL_Surface * screen;

    SDL_Init(SDL_INIT_EVERYTHING);
    screen = SDL_SetVideoMode(800, 600, 24, SDL_SWSURFACE);

    SDL_FillRect(screen, &screen.clip_rect, SDL_MapRGB(screen.format, 
                                                       0xFF, 0x00, 0x00));
    SDL_Flip(screen);

    SDL_Delay(6000);
    return 0;
}

This is my sample test program. First of all I downloaded SDL development libraries for VC6

Than you need to convert library files to OMF format. I preferred coff2omf tool which ships with Borland C++ Compiler because it is free. DigitalMars has a tool with same name but it isn't free. Which doesn't make sense to me.

coff2omf.exe SDL.lib SDL2.lib

And than I compiled and linked like that:

dmd -c test.d sdl.d

link test.obj sdl.obj SDL2.lib

It works for me.


Also if you need D bindings for SDL library you may download from here. File name is sdl.d but not complete yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜