4

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

Why doesn't the libs wrap everything in it?

symfony
  • 915
  • 2
  • 13
  • 20
  • your question isn't clear, but you seem to be confused. header files aren't added to compilation - they're in source and (maybe) makefiles. Post what you have (and accept an answer every once in a while) – KevinDTimm Mar 25 '10 at 14:33
  • Funny enough the question is interesting enough to have been discussed in the C++ standards committee... and is still in the air for a later update after C++11 – David Rodríguez - dribeas Mar 25 '10 at 15:10

3 Answers3

5

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
  • 74,820
  • 18
  • 121
  • 166
1

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
  • 104,103
  • 58
  • 317
  • 552
  • So it's just used for compile time,and ignored at run time? – symfony Mar 25 '10 at 14:36
  • 3
    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 Mar 25 '10 at 14:39
-1

I'm guessing this is your way of handling the question you asked at 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.

Community
  • 1
  • 1
KevenK
  • 2,975
  • 3
  • 26
  • 33
  • 2
    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! –  Mar 25 '10 at 14:37