The difference between putting the path in the source code (#include) and using GCC’s -I option (the portable approach) lies in where the path information resides.
The GCC method is always preferred in professional projects.
Non-Portable Method: Put the Path in the Source Code
By using a relative path in the #include, you are forcing all developers and all tools to use that exact folder structure.
include "../library/file.h"
If you move the library folder, you need to edit all the .c files that are included in it
The C preprocessor follows that explicit path from the location of the main.c file
Portable (Professional) Method: Use GCC’s -I Option
include "file.h" // Clean and simple path!
gcc command
gcc main.c -I /home/user/project/library -I other/headers/folder …
The source code (main.c) never changes, no matter where the library is located on disk. The path is set only once in the compilation command (or in the Makefile).
The developer only needs to know the name of the header file, not where it is in the file system.
The -I (Include path) option adds the specified directory to the list of places that GCC will check before searching the standard system paths.
Using -I keeps your C code generic and readable (#include “file.h”), while the build system configuration (the Makefile, or the gcc line in this case) takes care of resolving environment-specific paths. This is what makes a project robust and maintainable.