Search code examples
openglsdld

Using Derelict3 under DMD2 (D)


I've been using D for around a month now after using other languages such as C++ and Java. I've been wanting to move my simple game platform from Java to D, and I'd like to use the Derelict3 library to do so. I've compiled the github repository located here https://github.com/aldacron/Derelict3

Running Linux, if that helps.

I've placed my .a files in /usr/lib/.. and I've placed my .d files (The import folder from the Derelict root directory) in /usr/include/i386-linux-gnu/dmd/druntime/import

My code is as follows:

import std.stdio;

import derelict.opengl3.gl3;
import derelict.glfw3.glfw3;

pragma(lib, "/usr/lib/libDerelictUtil.a");
pragma(lib, "/usr/lib/libDerelictGL3.a");
pragma(lib, "/usr/lib/libDerelictGLFW3.a");

void main() {
    DerelictGL3.load();
    writeln("This is a line");
}

this is based on other questions that were answered on stackoverflow and some topics from the dlang.org forums, but the terminal spits this out at me when I'm compiling:

kevin@kevin-Latitude-D620:~$ dmd main.d
/usr/include/D/Derelict/libDerelictGL3.a(gl3.o): In function `_D8derelict7opengl33gl318_sharedStaticDtor2FZv':
../import/derelict/opengl3/gl3.d:(.text._D8derelict7opengl33gl318_sharedStaticDtor2FZv+0x4): undefined reference to `_D8derelict4util6loader15SharedLibLoader19isAutoUnloadEnabledOFNdZb'
/usr/include/D/Derelict/libDerelictGL3.a(gl3_d1_649.o):(.data+0x38): undefined reference to `_D8derelict4util6loader15SharedLibLoader7__ClassZ'
/usr/include/D/Derelict/libDerelictGL3.a(gl3_d1_649.o):(.rodata+0x4418): undefined reference to `_D8derelict4util6loader15SharedLibLoader4loadMFZv'
(MORE of the above)
collect2: ld returned 1 exit status
--- errorlevel 1

Solution

  • ld, the linker maintains a list of unresolved symbols as it moves first to last through the libraries to link, trying to reduce its list of unresolveds. This means that any dependencies should be listed after the code which depends on them. So try rearranging your pragma(libs...) like this:

    pragma(lib, "DerelictGL3"); 
    pragma(lib, "DerelictGLFW3"); 
    pragma(lib, "DerelictUtil"); 
    pragma(lib, "dl");