Including a header file from another directory

限于喜欢 提交于 2019-12-03 09:21:36

When referencing to header files relative to your c file you should use #include "path/to/header.h"

The form #include <someheader.h> is only used for internal headers or for explicitly added directories (in gcc with the -I option).

write

#include "../b/structure.h"

in place of

#include <structures.h>

then go in directory in c & compile your main.c with

gcc main.c

If you work on a Makefile project or simply run your code from command line, use

gcc -IC main.c

where -I option adds your C directory to the list of directories to be searched for header files, so you'll be able to use #include "structures.h"anywhere in your project.

If you want to use the command line argument then you can give gcc -idirafter ../b/ main.c

then you don't have to do any thing inside your program.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!