symfony
symfony

Reputation: 925

What's the relationship between header files and library files in c++?

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

Why doesn't the libs wrap everything in it?

Upvotes: 4

Views: 1596

Answers (3)

Tyler McHenry
Tyler McHenry

Reputation: 76630

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.

Upvotes: 5

KevenK
KevenK

Reputation: 3021

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.

Upvotes: -1

Billy ONeal
Billy ONeal

Reputation: 106530

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.

Upvotes: 1

Related Questions