2

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?

3
  • 5
    Possibly because those two headers have the .h extension and unordered_map does not? Commented Jul 29, 2011 at 16:09
  • Header files without a .h are usually C++ includes. Header files with a .h are usually C #includes Commented Jul 29, 2011 at 16:10
  • @Paul R: Not really. Extensionless headers are part of the C++ standard library. OP should also be saying <cstdio>. Commented Jul 29, 2011 at 17:14

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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.

4 Comments

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.
I didn't say it was the same, I said it wraps stdio.h.
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 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 :-)
0

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.