-lib question(s)

Jesse Phillips jessekphillips+D at gmail.com
Sun Apr 29 19:49:20 PDT 2012


On Saturday, 28 April 2012 at 05:37:20 UTC, Joshua Niehus wrote:

> Q1) The template version of hello seems to work, but the 
> simpleton version doesn't. What am i missing?
>
> Q2) Shouldn't I be compiling world.d with -lib and then put 
> world.a in some linker directory? I did that but got nowhere 
> fast.  Basically I have my .a file and a bunch of lame scripts 
> that need to use functions from it, its in a -L dir listed in 
> my dmd.conf, but nothing compiles.

Sounds like linux, you are correct that you'll want libworld.a in 
a path specified by -L-L

However you also will need to specify the library you want to 
load: -L-lworld

More detail.

The compiler needs to know the signatures of functions it is 
calling. It does this by reading "header" files. In D's case 
source files will do. These files are searched for from your 
include paths which are specified with -I

Once compilation is complete the compiler make a call to the 
linker. Linker commands are passed through with -L. The linker 
needs to know two things, where to find library files (defaults 
with /usr/lib and /usr/local/lib), and also what libraries to 
load.

Libraries have a special naming convention which starts with 
'lib' the name of the library, and an extension of .a or .so. 
This way you can request the library by name, -lworld, and it can 
be found. When using dmd you give command to be passed to the 
linker -L-lworld.

Alternatively you could just pass the library to the compiler, 
libworld.a.


More information about the Digitalmars-d-learn mailing list