21

In the root directory, we can find several 'lib' subfolder, for example, /lib, lib32, lib64, /usr/lib, /usr/lib32, /usr/local/lib.

What are their differences?

Braiam
  • 67,791
  • 32
  • 179
  • 269
tqjustc
  • 810

1 Answers1

32

/lib contain "essential" libraries that may be needed even in single-user (admin-only) mode and without /usr mounted

/usr/lib are the libraries for the normal user-programs, that mostly can be found under /usr.

/usr/local/lib are the libraries for locally installed programs and packages ie. things you've compiled and installed from source-packages yourself.

In addition to shared and static libraries which are the lib-directories main purpose, you may also find some hierarchies (with their own lib, bin, include and so on) for some larger packages under them.

lib32 and lib64 are used on 64-bits systems to separate libraries for 32-and 64-bits.

green
  • 14,306
  • for the specific 'lib' file in '/usr/local/lib', how can I include it in my program ? Thanks – tqjustc Apr 15 '13 at 17:09
  • 2
    The command ldconfig updates the system's cache over libraries, so after installing a new library, you should run this. There is also a config-file /etc/ld.so.conf which specify where ldconfig will look for new libraries, and you can add unusual library-location - like libraries with the actual lib-files in their own subdirs. /usr/local/lib should already be there, so if your library was installed directly under /usr/local/lib, running ldconfig should be enough. More in part #2 – Baard Kopperud Apr 16 '13 at 13:19
  • 2
    Now the system knows where the library is, but often you need to specify unusual libraries to the gcc and g++ compilers and linker as well. In your program you use #include to specify the library's header file. To compile: "gcc -Wall -I/path/to/includefile -c myprogram.c" Here it's probably /usr/local/include, which should be found anyway. To link with the library, you would use the command "gcc -L/path/to/library -lnameoflibrary -lotherlibraries myprogram.o" Again, /usr/local/lib should be found automatically, but if the lib was in a subdir, you surely would need to specify. – Baard Kopperud Apr 16 '13 at 13:25