Bug 3564 – Rdmd failing to link external C libraries
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-12-02T00:33:00Z
Last change time
2015-06-09T01:28:30Z
Assigned to
andrei
Creator
pelle.mansson
Comments
Comment #0 by pelle.mansson — 2009-12-02T00:33:57Z
I try to run D-code with an externally linked C library in this example:
~/dee% dmd test.d -L-lSDL
~/dee% ./test
~/dee% rdmd test.d -L-lSDL
/tmp/.rdmd/rdmd-test.d-E6CBF3336CD9625C87A273ACDCCC0CF8/test.d.o: In function `_Dmain':
test.d:(.text._Dmain+0x9): undefined reference to `SDL_Init'
collect2: ld returned 1 exit status
--- errorlevel 1
With dmd it works fine, but with rdmd it doesn't link the library at all. Dry run looks like this:
~/dee% rdmd --dry-run test.d -L-lSDL
chdir '.' && dmd -v -o- 'test.d' >test.d.deps
dmd -of'/tmp/.rdmd/home/plol/dee/test.d.E6CBF3336CD9625C87A273ACDCCC0CF8' -od'/tmp/.rdmd/rdmd-test.d-E6CBF3336CD9625C87A273ACDCCC0CF8' 'test.d'
The code I run is this:
extern (C) { int SDL_Init(uint); }
enum uint SDL_INIT_EVERYTHING = 0x0000FFFF;
void main(char[][] args) {
SDL_Init(SDL_INIT_EVERYTHING);
}
Comment #1 by bus_dbugzilla — 2010-09-07T18:59:47Z
rdmd's parameter format is:
rdmd [RDMD AND DMD OPTIONS]... program [PROGRAM OPTIONS]...
The order is important.
This works fine:
------------------------
$ cat main.d
module main;
import theLib;
void main()
{
foo();
}
$ cat theLib.d
module theLib;
import std.stdio;
void foo()
{
writeln("In foo");
}
$ dmd theLib.d -lib
$ mv theLib.d hide-this-file-and-keep-it-out-of-the-way-theLib.d
$ rdmd -LtheLib.a main.d
In foo
------------------------
But be aware of this:
http://d.puremagic.com/issues/show_bug.cgi?id=4814
Comment #2 by bus_dbugzilla — 2010-09-07T19:01:56Z
There's one more file I forgot to include in my example above:
--------------------
$ cat theLib.di
module theLib;
void foo();
--------------------
Comment #3 by bus_dbugzilla — 2010-09-07T19:19:08Z
Reopening, didn't notice this was regarding linking to C.
Comment #4 by andrei — 2011-06-05T16:18:46Z
I can't reproduce this, seems to be a simple inversion of arguments. Use this:
rdmd -L-lsomelib somefile.d
NOT
rdmd somefile.d -L-lsomelib
Trying it with a couple of C libraries does not show any symptoms.