Uzil
Uzil

Reputation: 31

Cannot include header files correctly

I'm having an issue where I'm adding some includes

#include <stdio.h>
#include <unordered_map>
#include <mysql.h>

Using this command to compile,

g++ -Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX -I/usr/include/ -I/usr/include/c++/4.5/bits/ main.c -o program

When i remove the .h on MySQL and stdio it says that it cannot find them, yet it works find on the unordered_map. Wtf?

Upvotes: 2

Views: 1688

Answers (4)

Mark B
Mark B

Reputation: 96311

Since the ages of C, most headers have had an extension which is typically .h, and they directly correspond to files in the system. In C++ the standard explicitly specifies certain library components as having include directives not including any extension, such as <unordered_map>. These library includes aren't even required to correspond to a file, just that they provide the required interface when included. By contrast, mysql.h and stdio.h and real files that must be included by exact name.

In the case of stdio.h the C++ library defines an include <cstdio> that includes all the features of C's stdio.h but puts them in the std namespace instead of global (which was the only option in C).

Upvotes: 1

Gearoid Murphy
Gearoid Murphy

Reputation: 12126

C++ omits the ".h" from it's system header files to differentiate them from the C header files. Detailed here under the section titled "C++ Headers for the Standard C Library"

Upvotes: 0

Praetorian
Praetorian

Reputation: 109289

The file name extension is not optional! The reason you can say

#include <unordered_map>

instead of

#include <unordered_map.h>

is because the file is actually called "unordered_map", no extension.

C++ does have the cstdio header which wraps C's stdio.h so you can include that instead; but as for MySql.h, I don't know whether they ship such a replacement.

Upvotes: 0

Griwes
Griwes

Reputation: 9059

Some standard library headers are named for example "string", "vector" etc. You will find file "unordered_map" in your include dir, but you won't find file "mysql", only "mysql.h".

Upvotes: 1

Related Questions