What is the difference between .LIB and .OBJ files? (Visual Studio C++)

Michal Czardybon picture Michal Czardybon · Sep 1, 2009 · Viewed 13.8k times · Source

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?

Answer

Barry Kelly picture Barry Kelly · Sep 1, 2009

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.