头文件路径包含问题

头文件包含两种,系统头文件和自定义头文件,系统头文件不说了,格式统一,自定义头文件在包含的时候要注意路径,其实是头文件与主文件的相对位置关系的问题。

ps:另外,LInux和Windows下也有所区别。

举4个例子,应该就能看明白了。

一.

这种情况下,在main.c中包含头文件如下:

#include "fish.h" 或

#include "./fish.h" (Linux)    or  #include ".\\fish.h" (Windows)

二.

这种情况下,在main.c中包含头文件如下:

#include "../fish.h" (Linux)    or  #include "..\\fish.h" (Windows)

三.


这种情况下,在main.c中包含头文件如下:

#include "../文件夹2/fish.h" (Linux)    or  #include "..\\文件夹2\\fish.h" (Windows)

四.


这种情况下,在main.c中包含头文件如下:

#include "文件夹3/fish.h" (Linux)    or  #include "文件夹3\\fish.h" (Windows)



版权声明:本文为ZHI11235813原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。