Discussion Forum

how to link only the used part of a lib file

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
shrikant dhapke
Posted
28-May-2012 12:37 GMT
Toolset
ARM
New! how to link only the used part of a lib file

Hi
I am using a lib file in my project which say contains in all 10 c functions. Now in different cases i tried to use total one or two or three or any number of functions from these lib file then also the complete library get linked and i don't see any change in the size of the output binary file that is created. In all cases the size of the output binary file is same i.e. 5KB. Can anyone tell me why i cannot see any difference between these different cases. In the map file i am able to see that all the 10 functions got some memory assigned. Do anybody have any solution on this.

Read-Only
Author
Per Westermark
Posted
28-May-2012 12:49 GMT
Toolset
ARM
New! RE: how to link only the used part of a lib file

The traditional task of linkers is to link complete object files.

And a library is a collection of one or more object files.

So the traditional way to create professional libraries is to split the source code into many small files, giving the linker a suitable granularity when selecting what to include.

Some specific compilers/linkers have moved some of the compiler functionality into the linker, giving the linker the ability to play around and cut/paste/finalize object code when linking. But that is not part of the C standard, and not part of the behavior of the system-supplied "standard" linker.

If function A always calls function B, and function B is never expected to be called from anything but function A, then it is suitable to have function A and B in the same source file. Else, you should consider having them in individual source files.

So if you look at big runtime library source trees, you are likely to find:
fputs.c
fprintf.c
fgets.c
...

Often (almost) one source file for every exported library function.

Next Thread | Thread List | Previous Thread Start a Thread | Settings