2

I am new to software development, and over the course of compiling about 20 programs and dependencies from source I have seen a rough pattern, but I don't quite get it. I'm hoping you could shed some light on it.

I am SSHing on a SLC6 machine and without root permissions, I have to install all the software dependencies and the most difficult part - to LINK them to the right place.

For instance: I need to install log4cpp. I download a tarball and unpack it

./autogen.sh (if there isn't this one, just continue to next)
./configure
make

So It is installed in the folder itself along with the source code, just lying there dormant, until I can call it in the right way.

Then there is an other program which I need to install, and it requires me to specify the lib and include dirs for some dependencies

--with-log4cpp-inc=
--with-log4cpp-lib=

For SOME source compilations, the folder has a lib, bin and inc or include dir - Perfect! For some, the folder has just lib and inc dir. For some, the folder has just inc dir.

I have no problem when they all have a nice folder, easy to find. But I often run into problems, like with the log4cpp.

locate log4cpp.so

returns null (The lib dirs have .so files in it? or do they?)

So I have a problem, in this specific instance, that the library dir is missing and I cannot find it. But I want to know how to solve the problem every time, and also have some background information. However my googling skills seem to return nothing when searching for how library, include and bin environment variables work. I have also tried looking up the documentation for the program, but it seems that the questions I have:"Where is the lib dir, where is the include dir, where is the bin dir?" are so trivial, that they do not even need to communicate it.

So:

  • What is an include dir, what does it do, contain, how do I find it.
  • What is a library dir, what does it do, contain, how do I find it - every time - useful commands perhaps.
  • What is a binary dir, what does it do, contain, how do I find it.
  • I changed your title since this isn't really about environment variables. – goldilocks Oct 29 '14 at 16:18
1

Library files are usually prefixed with lib; your locate command might have been more successful if you were less specific: locate "*log4cpp*".

With regard to shared libraries (i.e., .so files -- this is usually but not necessarily the case; see "What is a library dir?" below) whereis will usually find the appropriate path but does not support globbing, so you'd have to get the name right, sans suffix (whereis liblog4cpp). ldconfig -p is even better, because you are getting the information straight from the horse's mouth (ldconfig configures the cache used by the linker, which manages shared libraries).

ldconfig -p | grep log4cpp

Note that to build against the library, you also need the relevant include header, which is probably not installed by default by the distro; those come in separate -dev or -devel packages.

What is an include dir?

An include directory contains C and C++ header files that are used this way in source code:

#include <foobar.h>
#include <foo/bar.h>

They are are organized into hierarchies, some of which is stipulated by (C/C++) language standards. However, the path to the top of the hierarchy is specific to the system and known to the compiler/preprocessor. E.g., these two files might be found at /usr/include/foobar.h and /usr/include/foo/bar.h.

Linux systems usually have two top level include directories in play, /usr/include and /usr/local/include (the latter takes precedence).

Include files are not necessary to the compiled software, only to creating them, which is why installing libfoobar from a distro package will get you libfoobar.so but not foobar.h. That's in the libfoobar-dev package (nb. naming conventions vary somewhat across distros).

What is a library dir?

A library directory contains libraries of two forms, dynamic (aka. shared) and static. Most of them are the former. They correspond roughly to include directories but there's often more of them (/lib, /lib64, /usr/lib, /usr/local/lib, etc.; some of those may be symlinks to others).

A shared library is one which is used at runtime; if an executable links to a shared library, (parts of) both of them are loaded into memory as necessary in order for the program to run. If something is already using the library, it is already in memory and does not have to be loaded again; the two applications will not interfere with each other since the shared part is read-only to them. Shared libraries by convention use the suffix .so.

A static library is built into an executable at compile time and is not subsequently necessary to run the executable. This is less common because the library cannot be shared with other applications, which potentially wastes a considerable amount of RAM. Static libraries by convention use the suffix .a.

What is a binary dir?

A binary directory contains executable program files, such as ls or firefox. Executables in the *nix world do not use suffixes. These directories are usually in the $PATH variable, otherwise you would have to type /usr/bin/ls all the time. Which executable will be used when you type ls can be determined with the whereis or which command.


If .configure allows you to specify a library or include directory, you usually only have to do so if it is in a non-standard place. Try it without, and if it is not found, then use the --with-inc= option.

1

The Standard Process when installing a package from source is as follows:

  1. ./configure
  2. make
  3. Optional: make test or make check
  4. make install

On a binary Distribution like Debian or Fedora, the above four commands are run in a central location and then packaged by the distribution maintainers for release to the public, where the users download them as updates or new packages in the package manager. On a source based distribution like Gentoo or Arch, the package manager runs the 4 commands listed, in the order listed.

In either case, it's up to the package manager software for your system to manage the dependencies your tracking down if your system has one, otherwise your missing step 4. Once Step 4 is run, the libdirs and the bindirs can be found by the configure scripts for all the other packages you compile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.