1

I have my own header files and libraries, which I don't want to copy for every new project, since this makes fixing bugs or adding new features to the library difficult. So I want to put them in a 'public' directory like /usr/include or /usr/local/include and their library counterparts, but I don't know where I am messing with the system! I could create my own directory and specify it with every compile, but that's cumbersome. Where can I put those files? I found a question about that, where the answer is /usr/local/include, but I read somewhere that it is used for the package manager, is that true?

2 Answers 2

1

If the applications are to be used by all the user in the system, the /usr/local tree is the ideal place; no package should put files there (it is for software you are compiling yourself), but the directory /usr/local/lib is in the default path for the dinamyc loader. (see /etc/ld.so.conf.d/libc.conf).

I normally even move the /usr/local tree under /home (just by moving the directory /usr/local to /home/local, and then symlinking /usr/local -> /home/local) so that it survives a complete reinstall(1).

If the applications are just for your user, I normally create $HOME/lib, $HOME/include and then play with environment variables or compiler flags to point to them.


Footnotes

(1) I normally install / and /home on separate partitions, but this is a very personal choice.

3
  • So I move "myheader.h" simply to /usr/local/ and "libmylib.a" to /usr/library/. Then I include with #include <myheader.h> and link the library with the compiler option -lmylib, right?
    – Kapichu
    Aug 8, 2014 at 12:37
  • I ment /usr/include, of course. But why not put it into /usr/local/include? What's the difference?
    – Kapichu
    Aug 8, 2014 at 13:14
  • No. The /usr/local is the tree. Includes go to /usr/local/includes, library to /usr/local/lib, configuration files to /usr/local/etc...
    – Rmano
    Aug 8, 2014 at 14:45
0

I have created the convention of creating a new local directory in /usr/local. so it's /usr/local/local/lib for me. This allows other developers to release their stuff into /usr/local and you then don't get any file name clashes. If you then want to publish and move your stuff to /usr/local/lib and /usr/local/include you may need to make a name change across all your source and make files, which will be a pain, but sed will help if you take care and proceed with caution. When you have libraries in /usr/local/lib or any where that is non-standard you have to set the environment variable LD_LIBRARY_PATH, so executing programs know where to look to link themselves.

You must log in to answer this question.

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