开发者

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-func开发者_高级运维tions -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?


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


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


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.


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜