As for your project source tree layout, a common setup looks like this:
src/
this is were your .cpp
files go
include/
for header that should get installed when you are writing a library
data/
is where graphics, icons, sounds, etc. go
external/
for git submodules or external libraries your project requires and that are obscure enough that you don't want users to manually install them
- a build file in the top level directory (autoconf/automake was used historically, but these days CMake seems to be more popular)
- a README or README.md explaining what the project does and which dependency it needs
Naming and organisation can of course vary between projects, there is no real standard, some use Source/
instead of src/
. Some might have the headers within the src/
directory and so on. It's really up to your projects needs. If a library is commonly shipped with most distributions there is no need to include it in the source tree. Same with most programming tools, git, gcc and Co. are provided by the Linux distribution and you don't have to worry about where they go.
If you are writing a library you might also want to looking into pkg-config
and the .so
naming rules.
As for installation directories, the FHS explains that in detail, short summary:
/usr/bin
for executables
/usr/lib
for public libraries
/usr/lib/${APPNAME}
for private libraries
/usr/include
for public header files
/usr/share/${APPNAME}
for data files
/opt/${APPNAME}
is used by some commercial products instead of spreading the data over the hierachy
/usr
itself is reserved for distribution installed packages, manually compiled stuff should go to /usr/local
instead. Most build systems will have a --prefix=PREFIX
option to allow the user to change that.
If you need to compile a library yourself, I would generally recommend to avoid installing it into /usr/local
, as uninstalling software from there is hard and it also makes it impossible to keep different versions of the same software around at the same time.
Instead install software it into a PREFIX of it's own, something like ~/run/somelibrary-0.0.1
. Installing software in such a way has however the disadvantage that tools won't find it. You can fix that by setting a few environment variables, I use a simple bash function for that purpose:
function activateprefix {
PREFIX="$1"; \
export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig/"; \
export LD_LIBRARY_PATH="${PREFIX}/lib/"; \
export LD_RUN_PATH="${PREFIX}/lib/"; \
export LIBRARY_PATH="${PREFIX}/lib/"; \
export CPLUS_INCLUDE_PATH="${PREFIX}/include/"; \
export C_INCLUDE_PATH="${PREFIX}/include/"; \
}