By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

difference between .obj and .lib

P: 11
plz anyone help me in order to better understand the difference between .obj and .lib files
Jun 14 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
An object file (.obj) is the result of compiling your source code.

A library (.lib) is precompiled code provided for you.

Let's assume you use printf() in your program. When you compile the code, all the compiler sees is the function prototype of printf() so it doesn't generate an error but it does mark your object file (.obj) with an unresolved external reference for printf().

During the link step of the build, the linker wants to copy your .obj to your .exe. But it sees the missing prinft(). Now the linker looks in libraries (.lib) for the code for printf(). When it finds it, is copies the printf() code to your .exe, then copies your .obj to the .exe and then fixes the addresses inside the .exe so that any call to printf() now goes to the copy of printf() inisde the.exe. This is the link.

Libraries may be provided by your compiler vendor or you may create libraries yourself.
Jun 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.