Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relationship of .lib and .obj to each other and my project in c++?

How do .lib and .obj files relate to each other? What is their purpose? Is a .lib just a collection of .obj files? If so are the .obj's then stored inside the .lib making the .obj's unnecessary?

like image 644
Mr Bell Avatar asked Jan 23 '10 03:01

Mr Bell


1 Answers

Typically, the .obj files refer to object files. This is a source file in its compiled form. For example, a main.cpp and foo.cpp would produce main.obj and foo.obj.

It is then the linkers job to link them together, so that main.obj can reach functions defined in foo.obj and vice-versa. The linker will output your binary file, which is the .lib (or .a, or .exe, or .dll``, etc).

So in a loose sense, yes, the binary output (.lib in your case) is the collection of linked .obj files. Once you are finished compiling, and want to use the library, you only need other programs to link with the .lib. The .obj are what's considered intermediate files, and are not needed after linking is completed.

like image 152
GManNickG Avatar answered Sep 27 '22 20:09

GManNickG