Take the 2-minute tour ×

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?

share|improve this question
Possibly because those two headers have the .h extension and unordered_map does not? –  Michael Myers Jul 29 '11 at 16:09
Header files without a .h are usually C++ includes. Header files with a .h are usually C #includes –  Paul R Jul 29 '11 at 16:10
@Paul R: Not really. Extensionless headers are part of the C++ standard library. OP should also be saying <cstdio>. –  Kerrek SB Jul 29 '11 at 17:14
add comment

4 Answers

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".

share|improve this answer
add comment

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).

share|improve this answer
add comment

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.

share|improve this answer
cstdio is not the same as stdio.h, it wraps that into std namespace. Some implementations leave the symbols in the global namespace as a side-effect though, you should not count on that. –  unkulunkulu Jul 29 '11 at 16:13
I didn't say it was the same, I said it wraps stdio.h. –  Praetorian Jul 29 '11 at 16:14
I just clarified :) –  unkulunkulu Jul 29 '11 at 16:17
In fact, there doesn't have to exist a file called unordered_map at all -- the standard only mandates that if you say #include <unordered_map>, then you get to use the various defined classes and functions. –  Kerrek SB Jul 29 '11 at 17:15
@Kerrek SB Interesting, never thought of it that way. It would be fun trying to step into an std::unordered_map function if there was no file :-) –  Praetorian Jul 29 '11 at 17:23
add comment

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"

share|improve this answer
add comment

Your Answer


