Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between /lib/i386-linux-gnu/libc.so.6, /lib/x86_64-linux-gnu/libc.so.6 and /usr/lib/x86_64-linux-gnu/libc.so?

Tags:

gcc

64-bit

libc

I installed Matlab in my Linux Mint 14 Nadia (a uname -a shows: Linux Ideapad-Z570 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux) and when calling it from the command line I would get a: "/lib64/libc.so not found".

I followed the help on mathworks by making a link in /lib64 as:

ln -s /lib/x86_64-linux-gnu/libc.so.6 .

That solved the issue.

Now, if I do a locate of this library I get:

locate "libc.so"
/lib/i386-linux-gnu/libc.so.6
/lib/x86_64-linux-gnu/libc.so.6
/usr/lib/x86_64-linux-gnu/libc.so

I will be compiling with gcc in this computer and I would like to have full 64bit compilations. What does exactly mean to have all these different libc.so libraries? which one will the gnu compiler be using? do I need to do anything different with gcc to compile for 64 bits?

I would also love to optimize as much as I can for my new i7 core!!!

like image 539
Alejandro Avatar asked Dec 09 '12 19:12

Alejandro


1 Answers

/lib/i386-linux-gnu/libc.so.6

This is is 32-bit version of the library.

/lib/x86_64-linux-gnu/libc.so.6

This is the 64-bit version of the library.

Both are usually symbolic links to the actual library file, which will usually be named according to the glibc release number, for example libc-2.15.so

/usr/lib/x86_64-linux-gnu/libc.so

This is not a library, but a linker script file, which refers to the above symlinks.

Why do we need all these:

First, regardless of libc version installed, the linker will always search for libc.so, because the compiler driver will always pass to the linker the -lc options. The name libc stays the same and denotes to most recent version of the library.

The symlinks libc.so.6 are named after the soname of the library, which, more or less corresponds to the ABI version of the library. The executables, linked against libc.so in fact contain runtime dependencies on libc.so.6.

If we imagine the someday a grossly ABI incompatible libc is released, it's soname could be named libc.so.7, for example and this version coukld coexists with the older libc.so.6 version, thus executables linked against one or the other can coexist in the same system,

And finally, the name libc-2.15.so refers to the libc release, when you install a new libc package, the name will change to libc-2.16.so. Provided that it is binary compatible with the previous release, the libc.so.6 link will stay named that way and the existing executables will continue to work.

like image 174
chill Avatar answered Oct 09 '22 17:10

chill