I'm planing to make several projects in C and C++ under Linux. In some projects I will need additional libraries. Correct me if I'm wrong. I'm planning to store libs in /usr/local/include
. But is it good practice to mix all libs in one directory? Maybe it is better to create libs name subdirectories in /usr/local/include
directory? And maybe it is better to store headers and source in different directories? Best practice is needed.
How to deal with not compiled libs like for example MiniIni
https://code.google.com/p/minini/. It comes with header and C files. Should I compile it and place in /lib
directory and headers to /include
. Or maybe it is better place everything in /include?
If you talk about libs I assume you mean compiled libraries (.so
files or .a
files). Those should go into /usr/local/lib/
. Headers should go into /usr/local/include
. Sources .cpp
files usually should not go anywhere in the installation. Sometimes it is necessary to install them, so they can be rebuild on demand (dkms comes to mind). Then the sources should go into /usr/local/src/project_name/
.
I personally prefer headers and libs to be installed in sub-directories of /usr/local/include
and /usr/local/lib
, but not everybody will agree.
The /usr/local
prefix always should be configurable. While a traditional make install
should use it as a default, packagers on distros will certainly change it to install directly into /usr
.
I hope you aren't storing libs in /usr/local/include. They belong in /usr/local/lib or possibly /usr/local/lib64.
Headers needed for individual projects should NOT go into /usr/local/include, they should stay with the project. Only put stuff into /usr/local/lib and /usr/local/include if you are building a library to be included in several of your projects. Even then, i'd keep the headers local to the project, and only copy them to /usr/local/include as part of the build process.
As to same directory or different within your project tree, it depends on how big the project is. I typically start moving stuff into seperate directories when the number of files (source + include) starts exceeding 20.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With