Search code examples
compiler-errorssdldundefined-symbol

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./lib/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?


Solution

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