help understanding import libraries

maarten van damme maartenvd1994 at gmail.com
Fri Aug 19 08:23:56 PDT 2011


I'm really getting confused as to how import libraries actually work.
Someone once told me that in order to use an import library one has to write
d files declaring the functions so that the dmd compiler knows what's in the
lib files.
I've never thought any further untill I compiled the gtkd project to a lib
file.

the compiler flags I needed to add was -I for every src directory and -L for
the lib file. The problem with that was that those files in the src dir
don't declare the functions but also define them. They are the real source
code files so I didn't understand why the -L flag was necessary. I never
experimented further though :)

Today I've looked  in the lib files and saw that phobos.lib was there. just
for fun I decided to compile a simple hello world file and compile it with
the standard compiler options. Then I compiled without linking and did the
linking manually. The resulting executable was 146 kb while the executable
using the standard compiler options was almost 2 megabytes.

Is the compiler really including all the "garbage" I use from phobos from
the source files instead of linking to the phobos.lib file? Can I avoid
this? does the -L flag pointing to my gtkd.lib file actually do something?

Secondly I've also used implib to convert a dll file to a .lib file. The
resulting lib file was WAY smaller then the dll file so I concluded that the
lib file only contains information like this:
in dll XXX
function YYY at export adress Y
function ZZZ at export adress Z
...

But where does the lib file searches for the dll file? how can we control
that? Is my hunch right?

Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110819/98ac932e/attachment.html>


More information about the Digitalmars-d-learn mailing list