Where belongs custom header files?

In which directory at best I would move private header files so that the compiler find it by default?

I have to compile a program from github where some headers are was missed. I found them in the net, and now I'm unsure where I should them place at best so the compiler find it by default.

Or, alternatively, which environment variable(s) I need to change so the headers will be found by default?
https://www.howtogeek.com/117435/htg-explains-the-linux-directory-structure-explained/
The most likely place if they're not well known packages (ie ones your distro package manager would install) would possibly be /opt

But to be safe, create your own $HOME/libs and set LIBRARY_PATH
https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
Does your distro have package management? If yes, then files are preferentially installed from packages (that contain metadata to also uninstall in managed fashion).

You did find the headers, but did you check that no package repository for your distro has them in packages?


If the headers are not packages and you are the only one using them, then best option is to have them under your $HOME and tell the compiler&linker where to look from (the -I and -L options).

You probably pass options to compiler via Makefile which in turn is generated by configure, cmake, IDE, etc.
It depends on your OS.

I'm using macOS X High Sierra, and my include files are in my /usr/include directory. If I move files to it, I can use
 
#include <whatever> 

But there's another way.
You can put the files in whatever directory your programs are stored in and use
 
#include "whatever" 

and that works too, although you can only use it for programs stored in the same directory.
although you can only use it for programs stored in the same directory

The compilers I work with let you give a -I myDirectory command line option to specify where to look for files included with #include ""
Both #include "foo" and #include <foo> seek from multiple paths.

Read the documentation of preprocessor with man cpp
(or one of the online copies, e.g. https://man7.org/linux/man-pages/man1/cpp.1.html but note that online version might not match the version of cpp that you have).

From that text seek the description of options -iquote and -isystem.
Topic archived. No new replies allowed.