views:

105

answers:

3

Why do we need to add both includes and libs to the compilation?

Why doesn't the libs wrap everything in it?

A: 

A header file (usually) only contains declarations for classes and functions. The actual implementations are built from CPP files. You can then link against those implementations with only the header declarations available.

Billy ONeal
So it's just used for compile time,and ignored at run time?
symfony
All declarations are essentially compile-time only. If you write your own function prototype, there's nothing that reflects the prototype in the compiled code. Now, the function *body* had better exist somewhere or your linker will complain, but it's the body that gets compiled, not the prototype.
Tyler McHenry
@symfony: Yes, that's right.
Billy ONeal
A: 

I'm guessing this is your way of handling the question you asked at http://stackoverflow.com/questions/2516187/how-to-make-include-mysql-h-work

Unfortunately, I think the better solution is to either learn more about C++, or learn more about Google, before posting absolutely everything to this site.

KevenK
Look over the OP's other questions... the same thing happened with an `extern`-related question yesterday. It's time to stop answering questions from this user!
+3  A: 

Header files define interfaces; libraries provide implementations.

The header for a library is going to tell your compiler the names and signatures of functions provided by the library, the names of variables provided by the library, and the layout of classes provided by the library.

The library itself is compiled code which is executed at run time. Using the header during compilation allows your compiler to generate compiled code which knows how to invoke and communicate with the existing library code.

Tyler McHenry