www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3564] New: Rdmd failing to link external C libraries

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3564

           Summary: Rdmd failing to link external C libraries
           Product: D
           Version: 2.034
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: pelle.mansson gmail.com



PST ---
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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 02 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3564


Nick Sabalausky <cbkbbejeap mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cbkbbejeap mailinator.com



18:59:47 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 07 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3564


Nick Sabalausky <cbkbbejeap mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



19:01:56 PDT ---
There's one more file I forgot to include in my example above:

--------------------
$ cat theLib.di
module theLib;
void foo();
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 07 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3564


Nick Sabalausky <cbkbbejeap mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |



19:19:08 PDT ---
Reopening, didn't notice this was regarding linking to C.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 07 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3564


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 08 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3564


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |WORKSFORME



16:18:46 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 05 2011