I have a question.
My current project has a header I include at the beginning. I include it like so:
#include <C:/Data/Programming/Project_2018/Files/header.h>
This is proving to be a problem as I can't make it portable to another computer. My question is, can I make some sort of change to the #include in order to force the compiler to seek this header.h in the same folder as the c file that uses it?
#include <.../Files/header.h>
With ... representing the folder where the main.c file is contained?
The final destination for this project is a zip folder which is to be delivered to be used on any computer, so I need this portability...
Any clues?
Yes, you can use relative includes in C. If you're compiling from the directory with main.c
in it, #include "header.h"
will work for you. Note the double quotes, which tell the compiler to look in the source tree, not the include path.
If your directory structure is something like this:
.../files/
.../files/main.c
.../files/include/header.h
then you'll want to #include "include/header.h"
. You can also move up the tree, so with
.../files/src/main.c
.../files/include/header.h
you can #include "../include/header.h"
. The path is unix-y, and in unix land, ..
is the parent directory.
This question might also be relevant.