Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 308
Michal Czardybon Avatar asked Sep 01 '09 07:09

Michal Czardybon


People also ask

What is .LIB file in Visual Studio?

The Microsoft Library Manager (LIB.exe) creates and manages a library of Common Object File Format (COFF) object files. LIB can also be used to create export files and import libraries to reference exported definitions. You can start this tool only from the Visual Studio command prompt.

What are .obj files in Visual Studio?

Object files contain relocatable machine code that is generated from your source code. Visual Studio creates one .

What is the use of .LIB file?

A LIB file contains a library of information used by a specific program. It may store a variety of information, which may include functions and constants referenced by a program or actual objects, such as text clippings, images, or other media.


1 Answers

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.

like image 79
Barry Kelly Avatar answered Sep 23 '22 13:09

Barry Kelly