5

I just downloaded some new header files and have a folder of them that I wish to make available. First, I would like to make them available to any file wishing to use them. So, I would like to be able to include the new header file (call it newheader.h) where I want, just like math.h, for example. Where should I put it?

Second, I wish to make these files available to all users. I have root permissions. Is there a special directory I need to put it in? Thanks so much!

3 Answers 3

10

Store them in /usr/local/include. From http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/usr.html, items in this directory are "... safe from being overwritten when the system software is updated", which is important since you do not want the headers files you have downloaded to get clobbered by system updates, which might happen if you put them in /usr/include.

3
  • Do I have to include the entire pathname? Is it possible to make it so that I just have to write #include "cuba.h" or #include <cuba.h> at the top of a C file?
    – paulinho
    Mar 19, 2018 at 1:04
  • 2
    @paulinho If you but cuba.h in in /usr/local/include, use #include <cuba.h>. If you put foo/cuba.h in /usr/local/include, use #include <foo/cuba.h>.
    – muru
    Mar 19, 2018 at 1:27
  • You can verify that /usr/local/include itself is in the default GCC include path using (for example) gcc -v -xc -E /dev/null 2>&1 | awk '/#include/,/End/' Mar 19, 2018 at 2:00
6

On MY system, the /usr/local/include/ directory exists, and is empty. The Filsystem Hierarchy Standard says (FHS 3.0) the directory to use is /usr/local/include. Files should be world-readable (0444) and directories should be searchable (0555).

1
  • 1
    It's perfectly reasonable for the directory to exist and be empty - YOU simply haven't added files yet. The whole point of that directory is that its contents vary between systems.
    – MSalters
    Mar 19, 2018 at 14:47
2

The question is, what do you want to achieve?

Usually you have three scenarios:

  • development
  • local installation (in your $HOME)
  • global installation

For the first 2, you should probably use the -I switch to give a path to the headers. The first would likely be -I../mylib/include, the second may be -I/home/user/local_libs/somelib/include.

The third one is a global installation, which should place them in /usr/local/include, but managed by a tool like automake or cmake. When packaging, the maintainer should adapt the installpath and/or the include path to install the headers to /usr/include.

When using automake you may have notices than the --prefix parameter defaults to /usr/local for a safe installation which does not interfere with system packages, while i.e. debian maintainers run ./configure --prefix=/usr in their package scripts. The include path is built from this prefix, so it follows the package installation.

3
  • The question implies global availability, so I think only your third option is relevant here. Mar 19, 2018 at 15:28
  • I am just not sure, if your own headers for something which is in development and not deployed as library to be used should be there or i.e. in /opt/our-dev-code/include or a copy per user. So I still have a bit the feeling if it is a X Y problem and the proper -I option is a better answer then deploying in /usr/local/include, so I elaborated a bit on the other options.
    – allo
    Mar 19, 2018 at 15:45
  • Its good to point out the development phase versus production libraries. There might also be a testing library post production. Mar 19, 2018 at 21:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .