beign able to include files using <file>
is generally bad practise, it increase the risk of files with same name became ambiguos (especially on big projects).
You can achieve that by specifing additional global include directories using the -I
compiler option. However there is no best way to achieve that (it depends on how project is organized and how it is big).
Include by absolute path:
#include <file>
#include <somepath/file2>
Pros:
- Source code structure is more flexibile (you can move your files without warrying about breaking compilation)
Cons:
- More chance of name clash between files
Include by path relative to source file:
#include "../file"
#include "../somepath2/file2"
Pros:
- No chance for name clash, there exist only 1 file given any relative path
Cons:
- You cannot move files around otherwise relative paths needs to be changed (however refactoring tools of your IDE may help with that)
Definitely I prefer using absolute path for standard library stuff and eventually FEW other dependencies, while otherwise I use only relative paths. You should note that when the compiler search for global include files, it will search in all provided -I
directories, so if you abuse that feature it is likely you will increase compile time.
Of course even when using global includes, I prefer adding just 1 extra directory and organize that so that the compiler doesn't have to guess paths
Include
+FolderNameSpace1
+FolderNameSpace2
So I have just to add the namespace when including
#include <FolderNameSpace1/File1>
Some open source projects, had this problem in mind, however since not all people is willing to spend too much time organizing folder structure, their developers used the more simple strategy to prepend a suffix on Header file names (to avoid name clash).. In example in Ogre you have to do:
#include <OgreFileName>
//or (depending on how your project is organized)
#include "../Deps/OgreFileName"
So after some premise, to answer your question,
you have to add as "global include directory" the directory that has all include files you want to use, so Given you are using GCC and your project is organized like that:
Project
+FFWT
+includes
+yourfolder
+yoour files
you have just to do:
gcc -Wall -march=native -O3 -ffast-math -I../FFWT/includes c -o main.o main.c
(I am assuming you are calling GCC from inside "yourfolder")
How to add additional global include directories: