What is the relationship between .lib and .obj with each other and my project in C ++?

How do .lib and .obj files relate to each other? What is their purpose? Is .lib just a collection of .obj files? If so .obj is then stored inside .lib, which makes .obj unnecessary?

+4
source share
3 answers

Usually .obj files are related to object files. This is the source file in its compiled form. For example, main.cpp and foo.cpp will create main.obj and foo.obj .

It is then that the task of the linkers binds them together so that main.obj can reach the functions defined in foo.obj and vice versa. The compiler will output your binary, which is .lib (or .a , or .exe , or .dll,, etc.).

So, in a free sense, yes, binary output ( .lib in your case) is a collection of related .obj files. After you finish compiling and want to use the library, you only need other programs to communicate with .lib . .obj is what is considered an intermediate file and is not required after the layout is complete.

+10
source

It depends. If the .lib file is a static library, then it is more or less just a collection of .obj files. If you create or use a DLL, then the .lib file is just an import library, with information about which characters are available in the corresponding DLL.

+2
source

Yes, a .lib file is just a collection of .obj files. Nothing has been done with the contents of the .obj files, the best analogy is the .zip archive. Yes, you can delete .obj files after creating .lib since .lib contains a verbatim copy of .obj files.

Remember that if you use .lib to distribute your product, you usually need to create 4 of them. Debug vs Release build and two versions of CRT (/ MT vs / MD).

+1
source

Source: https://habr.com/ru/post/1299180/


All Articles