Solved General question on linking libraries
-
If I am in a subdirs project, and building two static libs where libA depends on libB, should I expect libA.a to be larger than libB.a, ie should the static library contain the code for the static library it depends upon? Or am I getting muddled here?
In my case libA.a is ~16kB and liB.a is about 327kB. Now if the linking is sufficiently clever it could eliminate a lot of unused code, but that seems a bit of a stretch for my imagination. I am more inclined to believe that I have got the build wrong somehow......
Could someone clear some of the fog for me pleas?
-
@aethelnorn The final link step is done when the executable and all depending libs are put together.
Unti then, the linker cannot know which function from the library you are possibly using or not, and therefore needs to keep them all in.
-
@aha_1980 OK, so I have libA.a and libB.a and no code from libB has yet been included in libA. That makes sense. But what if libA.a were the ultimate product of this build? It would then need libB included in it. How could I tell the system that this was the case?
Another possibility in my case is that libA does include libB but uses so little of it that the size of libA does not increase much atall. I could almost beleive that (but not quite as the discrepency is large). Mind you, I have little feel for how much code 8kB represents.
-
@aethelnorn said in General question on linking libraries:
@aha_1980 OK, so I have libA.a and libB.a and no code from libB has yet been included in libA. That makes sense. But what if libA.a were the ultimate product of this build? It would then need libB included in it. How could I tell the system that this was the case?
I'm not absolutely sure here, but I think that static libs are never a final target, only shared libs or programs.
Another possibility in my case is that libA does include libB but uses so little of it that the size of libA does not increase much atall. I could almost beleive that (but not quite as the discrepency is large). Mind you, I have little feel for how much code 8kB represents.
Well, with my embedded background, that could be a complete program on a microcontroller ;)
Otherwise, really hard to tell
-
@aha_1980 said in General question on linking libraries:
@aethelnorn said in General question on linking libraries:
@aha_1980 OK, so I have libA.a and libB.a and no code from libB has yet been included in libA. That makes sense. But what if libA.a were the ultimate product of this build? It would then need libB included in it. How could I tell the system that this was the case?
I'm not absolutely sure here, but I think that static libs are never a final target, only shared libs or programs.
That would make sense, in a limited way. Static libs could be viewd as 'intermediates' and not final products. Does seem a bit limited if I were producing them for a JNI app. Or would that require dynamic libs? My ignorance shows through.Another possibility in my case is that libA does include libB but uses so little of it that the size of libA does not increase much atall. I could almost beleive that (but not quite as the discrepency is large). Mind you, I have little feel for how much code 8kB represents.
Well, with my embedded background, that could be a complete program on a microcontroller ;)
I know..... at college we wrote a pre-emptive multitasking operating system on a board with 1k and a 6800. Needed the only 4k board to run the debugger...
Otherwise, really hard to tell
I will worry about whether this step is successful once I get to the next step then.
-
@aha_1980 Yep, it was not completely linking.... next step gate an executable large enough to convince me - and executable runs so must have all the libs in it. Thanks again for your help.