Thread overview | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 19, 2011 help understanding import libraries | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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 |
August 19, 2011 Re: help understanding import libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to maarten van damme | maarten van damme Wrote:
> 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 :)
The process of creating an executable goes from generating machine code from source to linking the machine code for execution, as you know. The -I flag is the compiler import/include directory while -L is flags passed to the linker. That so while you may have complete source code in the import directory the compiler is only looking at the declaration and does not compile the files, it then informs the linker where the symbols can be found from the information you provide after the -L flag.
If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
|
August 19, 2011 Re: help understanding import libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On Fri, 19 Aug 2011 12:38:01 -0400, Jesse Phillips wrote:
> If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
Just a reminder, you have "dmd @cmdfile" for cases where you want to put a "long" command line's options into a file for easier management.
Graham
|
August 19, 2011 Re: help understanding import libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On Fri, 19 Aug 2011 12:38:01 -0400, Jesse Phillips wrote:
> If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
Just a reminder, you have "dmd @cmdfile" for cases where you want to put a "long" command line's options into a file for easier management.
Graham
|
August 19, 2011 Re: help understanding import libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On Fri, 19 Aug 2011 12:38:01 -0400, Jesse Phillips wrote:
> If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
Just a reminder, you have "dmd @cmdfile" for cases where you want to put a "long" command line's options into a file for easier management.
Graham
|
August 19, 2011 Re: help understanding import libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On Fri, 19 Aug 2011 12:38:01 -0400, Jesse Phillips wrote:
> If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
Just a reminder, you have "dmd @cmdfile" for cases where you want to put a "long" command line's options into a file for easier management.
Graham
|
August 19, 2011 Re: help understanding import libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On Fri, 19 Aug 2011 12:38:01 -0400, Jesse Phillips wrote:
> If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
Just a reminder, you have "dmd @cmdfile" for cases where you want to put a "long" command line's options into a file for easier management.
Graham
|
August 19, 2011 duplicates (Re: help understanding import libraries) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Graham Fawcett | On Fri, 19 Aug 2011 17:35:00 +0000, Graham Fawcett wrote:
> On Fri, 19 Aug 2011 12:38:01 -0400, Jesse Phillips wrote:
>
>> If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
>
> Just a reminder, you have "dmd @cmdfile" for cases where you want to put a "long" command line's options into a file for easier management.
>
> Graham
Sorry for the duplicate posts, I have no idea why that happened.
Graham
|
August 19, 2011 Re: duplicates (Re: help understanding import libraries) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Graham Fawcett Attachments:
| I saw the same with another user using the web interface, seems like it's buggy
2011/8/19 Graham Fawcett <fawcett@uwindsor.ca>
> On Fri, 19 Aug 2011 17:35:00 +0000, Graham Fawcett wrote:
>
> > On Fri, 19 Aug 2011 12:38:01 -0400, Jesse Phillips wrote:
> >
> >> If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
> >
> > Just a reminder, you have "dmd @cmdfile" for cases where you want to put a "long" command line's options into a file for easier management.
> >
> > Graham
>
> Sorry for the duplicate posts, I have no idea why that happened.
>
> Graham
>
>
|
August 19, 2011 Re: help understanding import libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Graham Fawcett | Graham Fawcett Wrote:
> On Fri, 19 Aug 2011 12:38:01 -0400, Jesse Phillips wrote:
>
> > If you wanted (and didn't run out of command line characters) you could list all .d files in every library you are using and have dmd compile everything for you. Then the -L would not be required.
>
> Just a reminder, you have "dmd @cmdfile" for cases where you want to put a "long" command line's options into a file for easier management.
>
> Graham
Yes but that just adds an extra lesson on top of learning what -I and -L do, why they are different and why both are used together.
|
Copyright © 1999-2021 by the D Language Foundation