View previous topic :: View next topic |
Author |
Message |
[insert witty name]
Joined: 19 Sep 2011 Posts: 2
|
Posted: Tue Aug 07, 2012 8:47 pm Post subject: linker error |
|
|
i was about to learn opengl / sdl in D but when trying to compile a simple program i seem to get an error from the linker, when i compile test.d with DMD using the command
Code: | dmd test.d -I/usr/include/x86_64-linux-gnu/dmd/ |
i get a test.o file (suggests it compiles correctly?)
but i also get an error:
Tried posting the error message on this board but it kept throwing some SQL related tantrum
if i add a -c flag and compile without linking dmd returns 0 suggesting this is definately a problem at the linking stage of things
does anyone know what is causing this?
code for test.d
Code: |
import derelict.opengl3.gl3;
import derelict.sdl2.sdl;
void main()
{
DerelictGL3.load();
DerelictSDL2.load();
}
|
|
|
Back to top |
|
|
BLM768
Joined: 22 Feb 2012 Posts: 13
|
Posted: Tue Aug 07, 2012 9:33 pm Post subject: |
|
|
It looks like you're not linking the Derelict libraries into your executable. You can either build Derelict using the instructions on the Derelict3 homepage (https://github.com/aldacron/Derelict3) or use rdmd instead of DMD to build it:
Code: | rdmd test.d -I/usr/include/x86_64-linux-gnu/dmd/ |
Rdmd automatically compiles all of your code's dependencies, including Derelict, but I haven't figured out how to keep it from stashing the resulting executable in its own cache directory instead of the current directory. It's fine for testing, though, because it will automatically run the program. |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Wed Aug 08, 2012 1:20 am Post subject: |
|
|
Your question has already mostly been answered. But I would like to add that when compiling with DMD (or GDC or LDC), any library you want to use with your program has to be compiled seperately and linked into your application when you build, or the source modules need to be compiled along side your application. Importing the modules makes the symbols available so that the compiler knows what you're doing, but it doesn't automatically compile the imports (the rdmd tool will do that for you).
As to your command line to link via dmd. First compile Derelict. Then, add the compiled libraries to your command line.
dmd -I/usr/include/x86-64-linux-gnu/dmd -L-L/path/to/DerelictLibs -L-lDerelictGL3 -L-lDerelictSDL2 -L-lDerelictUtil
You always need to link with DerelictUtil when using any Derelict package. _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
|