1

Hello I recently download Derelict2 by checking out the Derelict2 branch here and I try a little program with SDL :

import derelict.sdl.sdl;

int main()
{
  bool run = true;
  SDL_Init(SDL_INIT_VIDEO);
  SDL_SetVideoMode(400, 300, 32, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
  SDL_Event event;
  while(run)
  {
    SDL_WaitEvent(&event);
    switch(event.type)
    {
      case SDL_QUIT:
      run = false;
    } 
  }
  return 0;
}

I compile with this command line :

ldc2 -I=/usr/include/d/Derectlict2/DerelictSDL -I=/usr/include/d/Derectlict2/DerelictUtil -of=../bin/test -release -run main.d

but there is this error :

../bin/test.o: In function `_Dmain':
main:(.text+0x40): undefined reference to `_D8derelict3sdl8sdlfuncs8SDL_InitPUkZi'
main:(.text+0x69): undefined reference to `_D8derelict3sdl8sdlfuncs16SDL_SetVideoModePUiiikZPS8derelict3sdl8sdltypes11SDL_Surface'
main:(.text+0xa2): undefined reference to `_D8derelict3sdl8sdlfuncs13SDL_WaitEventPUPS8derelict3sdl8sdltypes9SDL_EventZi'
../bin/test.o:(.rodata+0x2c): undefined reference to `_D8derelict3sdl3sdl8__ModuleZ'
collect2: ld returned 1 exit status
Error: linking failed:
status: 1

I'm a really beginner in D and in programming in general, and I don't understand what's are the object file.

So if anyone understand what I did wrong please tell me

genpfault
  • 51,148
  • 11
  • 85
  • 139

2 Answers2

1

You need to link with Derelict2's libraries.

Below the imports, add:

pragma(lib, "relevant-libraries");

For example:

pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictGL.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictGLU.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictSDL.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictUtil.a");

If you are on Windows then those library files will be .libs

Alternatively, you can add the files to your build command by adding these flags:

-L/usr/inlcude/d/Derelict2/lib/libDerelictSDL.a -L/usr/ ... etc.

By the looks of things, you should only need to reference the SDL library.

Peter Alexander
  • 53,344
  • 14
  • 119
  • 168
  • there is a little problem, there is nothing in /usr/include/d/Derelict2/lib, how do I create those '.a' files ? (I'm on Linux) – Alexandre Hoffmann Nov 21 '11 at 08:45
  • Ah, you need to build them. Run `make -flinux.mak DC=dmd` in the Derelict2 directory (`DC=dmd` tells it what compiler to use). – Peter Alexander Nov 21 '11 at 08:50
  • make -flinux.mak DC=ldc2 returns this : make -C DerelictAL all PLATFORM=linux make[1]: Entering directory `/usr/include/d/Derectlict2/DerelictAL' Makefile:2: ../inc/ldc2_inc.mak: No such file or directory make[1]: *** No rule to make target `../inc/ldc2_inc.mak'. Stop. make[1]: Leaving directory `/usr/include/d/Derectlict2/DerelictAL' make: *** [DerelictAL_ALL] Error 2 – Alexandre Hoffmann Nov 21 '11 at 08:55
  • Derelict2 has a bunch of extra compiler specific make files to include in that `/inc/` directory. I see there is a `ldc_inc.mak` in there, just copy that: `cp inc/ldc_inc.mak inc/ldc2_inc.mak`. However, this probably means that it hasn't been tested with Derelict2... DMD is a safer bet if that's an option for you. – Peter Alexander Nov 21 '11 at 09:02
  • ok the .a files has been generated, thank you I will try to compile latter. I will confirme if it's works later – Alexandre Hoffmann Nov 21 '11 at 09:14
  • I've still a problem during the compilation, I compile with that command line : ldc2 -I=/usr/include/d/Derectlict2/DerelictSDL -I=/usr/include/d/Derectlict2/DerelictUtil -L/usr/include/d/Derectlict2/lib/libDerelictSDL.a -L/usr/include/d/Derectlict2/lib/libDerelictUtil.a -of=../bin/test -release -run main.d and I've got this output : – Alexandre Hoffmann Nov 21 '11 at 16:41
  • ../bin/test.o:(.rodata+0x2c): undefined reference to `_D8derelict3sdl3sdl8__ModuleZ' /usr/include/d/Derectlict2/lib/libDerelictUtil.a(compat.o):(.data+0xc): undefined reference to `_D3std4conv12__ModuleInfoZ' /usr/include/d/Derectlict2/lib/libDerelictUtil.a(compat.o):(.data+0x10): undefined reference to `_D3std6string12__ModuleInfoZ' collect2: ld returned 1 exit status Error: linking failed: status: 1 – Alexandre Hoffmann Nov 21 '11 at 16:48
  • Now it looks like it's even failing to link with Phobos2. Unfortunately I don't know anything about LDC2, so I can't really offer much help. Does a simple non-Derelict program compile and run? e.g. `import std.stdio; void main() { writeln("foo"); }`. If not then your problem is elsewhere. – Peter Alexander Nov 21 '11 at 20:06
1

Just use rdmd like that, second line.

Strange thing is though, that it complains about _D8derelict3sdl8sdlfuncs8SDL_InitPUkZi. Looks like an extern(C) is missing.

Trass3r
  • 5,858
  • 2
  • 30
  • 45