www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to link in a lib on cmd line?

reply "Nick Sabalausky" <a a.a> writes:
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? 
Sep 07 2010
next sibling parent "Nick Sabalausky" <a a.a> writes:
"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

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

import std.stdio; void foo() { writeln("In foo"); }
 dmd theLib.d -lib

 dmd main.d -LtheLib.lib

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"
Sep 07 2010
prev sibling next sibling parent reply Jonathan M Davis <jmdavisprog gmail.com> writes:
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
Sep 07 2010
parent "Nick Sabalausky" <a a.a> writes:
"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

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

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

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

------------------------ 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.
Sep 07 2010
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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

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

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

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

------------------------ 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
Sep 08 2010