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
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.
- 32,167
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.
- 422
- 1
- 4
- 11