Hari Krishna Nalla
Hari Krishna Nalla

Reputation: 199

How size of executable(.exe) affected using a static library which created compiling more source files in which some of them are not required for exe?

High level problem statement was explained in the header. Let me put the question with a simpler example as below. Lets say, I have created a static library(staticLib.a) using source files(A.c, B.c, C.c...Z.c). This static library(staticLib.a) was used to create a final executable(./finalExe). Final executable(./FinalExe) will use functions in A.c, B.c only at one instance.

So, My question is,

  1. Does rebuilding static library(staticLib.a) will really helps me in reducing the size of a final executable(./FinalExe)?
  2. (or) Linker will take responsibility of linking the required functions in A.c and B.c in static library(staticLib.a), and manages the final executable size dynamically? At another instance, final executable needs functions in D.c, E.c, in such case does linker would be able to manage the executable size dynamically?

Any suggestions would be highly appreciated!!

Upvotes: 0

Views: 383

Answers (1)

Employed Russian
Employed Russian

Reputation: 213416

The linker will pull object files (not sources) from staticLib.a as needed. Rebuilding the library to include fewer objects is not necessary.

Detailed description here or here.

Upvotes: 3

Related Questions