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?
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.
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.
来源:https://stackoverflow.com/questions/1361071/what-is-the-difference-between-lib-and-obj-files-visual-studio-c