Thread overview
How to link in a lib on cmd line?
Sep 08, 2010
Nick Sabalausky
Sep 08, 2010
Nick Sabalausky
Sep 08, 2010
Jonathan M Davis
Sep 08, 2010
Nick Sabalausky
September 08, 2010
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?


September 08, 2010
"Nick Sabalausky" <a@a.a> wrote in message news:i66oia$25s1$1@digitalmars.com...
> 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?

And I don't mean "with C" or anything like that, just ordinary D.

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

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

> dmd theLib.d -lib

> dmd main.d -LtheLib.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
OPTLINK : Warning 9: Unknown Option : NOITHELIB.LIB
main.obj(main)
 Error 42: Symbol Undefined _D3foo12__ModuleInfoZ
main.obj(main)
 Error 42: Symbol Undefined _D3foo3fooFZv
--- errorlevel 2

Same results for "-LtheLib".
I saw something about "-L-ltheLibNameHere" somewhere, but "-L-ltheLib.lib"
gets me:

OPTLINK (R) for Win32  Release 8.00.2
Copyright (C) Digital Mars 1989-2009  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 9: Unknown Option : LTHELIB.LIB
main.obj(main)
 Error 42: Symbol Undefined _D3foo12__ModuleInfoZ
main.obj(main)
 Error 42: Symbol Undefined _D3foo3fooFZv
--- errorlevel 2

And with "-L-ltheLib" the message just says "LTHELIB" instead of "LTHELIB.LIB"



September 08, 2010
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).

- Jonathan M Davis
September 08, 2010
"Jonathan M Davis" <jmdavisprog@gmail.com> wrote in message news:mailman.129.1283909879.858.digitalmars-d-learn@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.



September 08, 2010
On Tue, 07 Sep 2010 22:28:57 -0400, Nick Sabalausky <a@a.a> wrote:

> "Jonathan M Davis" <jmdavisprog@gmail.com> wrote in message
> news:mailman.129.1283909879.858.digitalmars-d-learn@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.

dmd just does a pass through:

-L<arg-to-pass-to-linker>

I have no clue what optlink's cryptic syntax is, but on Linux, it would be something along the lines of:

-L-Llibdir -L-lmylib

To give you an idea.  Now go find the command line syntax for optlink :)  Also, you can try dmd -v to see what link line it calls normally, I'm sure it has some of those options in there.

-Steve