GCC, path to libstdc++ for Ubuntu 11.04 x86

Asked by Stepan Dyatkovskiy on 2011-09-12

Hello. I'm using Ubuntu 11.04. And I found that libstdc++ and all other gcc libs are installed here:
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/<gcc version>
Note that directory name in /usr/lib started with "i386-..." . And its subdirectory begins with "i686".
So, my question is what the rule of path compilation for gcc libs? Will this path used for ubuntu 11.10?

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Last query:
2011-09-13
Last reply:
2011-09-13
mycae (mycae) said : #1

The path will be used for your compilation,

However, you can get linker errors about missing stdc++, if you don't use g++ to link, but instead use cc (thats cc, not a typo).

gcc invokes the correct compiler based upon extension. If you write gcc a.c -o a , and a contains c++ code, then it will attempt to link to name-mangled objects, and will fail.

Now, if you instead name your code .cpp, .cxx or .C (I think C is right..) then it will be implicitly linked to stdc++.

if you however call g++ explicitly on someting without a .cpp (or equiv) extention, then depending upon your gcc version, you may get linker errors which can be fixed by adding an explicit -lstdc++

I mean a little bit another problem. I writing tool that need to search libstdc++ automatically in OS without using of gcc. And now I need to implement the case for Ubuntu. I just want to know why in the first part of path contains "i386-linux-gnu" and why second part contains "i686-linux-gnu"? Why it uses two different triples in the path? By now the path looks strange for me.
Can you tell some formal description of path, e.g.:
<user libs>/<hardware-OS-toolchain triple>/gcc/<machine-OS-toolchain triple>/<gcc version>
where
<user libs> is default user libs place: "/usr/libs"
<triple> is a string like "i386-linux-gnu".

And will you use the same path to gcc libs in next versions of Ubuntu? Or it will be simplified to something like:
<user libs>/<triple>/gcc/<triple>/<gcc version>
where triple is
i386-linux-gnu for x86 machines, and
x86_64-linux-gnu for x86_64 machines.

mycae (mycae) said : #3

The triples are present to support cross-architecture compilation; eg a 64 bit machine might want to create 32 bit binaries (think build farm). You might be compiling for a completely different device, as in embedded systems, or even a completely different OS (think i386-mingw).

Remember that gcc itself is a wrapper -- the tool that does the link searching is the linker, ld. The manpage for "ld" is the most comprehensive description of the tool that I am familiar with (look for sysroot); I'd also recommend reading the blog entries of the guy who writes the GOLD linker.

http://www.airs.com/blog/archives/38

You might also want to look at the contents of /etc/ld.so.conf and /etc/ld.so.conf.d

mycae (mycae) said : #4

Oh, last point.

I don't work for canonical, I'm just answering questions on launchpad in my spare time. The packages come upstream from debian, though GCC is pretty key to the OS's function, so canonical can do what they like.

Canonical do not, to my knowledge, pay much attention to these forums -- you will only get community support here; so you may not get a definitive answer as to what will happen in the future. My money would be to read the debian gcc mailing lists (well, at least some subsection thereof)

Can you help with this problem?

Provide an answer of your own, or ask Stepan Dyatkovskiy for more information if necessary.

To post a message you must log in.