What is the difference between .LIB and .OBJ files

2019-02-04 03:23发布

问题:

I know .OBJ is the result of compiling a unit of compilation and .LIB is a static library that can be created from several .OBJ, but this difference seems to be only in the number of units of compilation. Is there any other difference? Is it the same or different file format?

I have come to this question when wondering if the same static variable defined in two (or more) .LIBs is merged or not during linking into the final executable. For .OBJs the variables are merged. But is it the same in .LIBs?

回答1:

A .LIB file is a collection of .OBJ files concatenated together with an index. There should be no difference in how the linker treats either.



回答2:

It seems like the .lib file is like a collection of .obj files. Some people also regard the process,that switch several .obj files to .lib files, as Archive. In that case, the .lib file is a box of .obj file, which could be treated equally by linker.