How to link in a lib on cmd line?

Nick Sabalausky a at a.a
Tue Sep 7 19:28:57 PDT 2010


"Jonathan M Davis" <jmdavisprog at gmail.com> wrote in message 
news:mailman.129.1283909879.858.digitalmars-d-learn at puremagic.com...
> On Tuesday 07 September 2010 18:23:59 Nick Sabalausky wrote:
>> I've tried all sorts of stuff and looked all over, but I'm completely at 
>> a
>> loss. How do I link in a static lib on the command line?
>
> Don't you just include it as one of the arguments, like all of the .d 
> files? I
> don't know. I haven't had a need to link in static libs before, and I 
> usually do
> the linking step myself with gcc so that I can get a static binary 
> (since -L-
> static doesn't currently work with dmd).
>

------------------------
> type main.d
module main;
import theLib;
void main()
{
    foo();
}

> type theLib.d
module theLib;
import std.stdio;
void foo()
{
    writeln("In foo");
}

> type theLib.di
module theLib;
void foo();

> dmd theLib.d -lib
> move theLib.d hide-this-file-and-keep-it-out-of-the-way-theLib.d
> dmd main.d theLib.lib

OPTLINK (R) for Win32  Release 8.00.2
Copyright (C) Digital Mars 1989-2009  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
theLib.lib
 Warning 140: Library probably needs FIXLIB

> main
In foo
------------------------

Ok, so that works, but with a linker warning. However, that can't be used 
with rdmd, becuase rdmd will interpret "theLib.lib" as the name of the 
program to be run.





More information about the Digitalmars-d-learn mailing list