The following compares CentOS 5 with FreeBSD 9.0:
The built-in gcc of CentOS 5 is gcc (GCC) 4.1.2, and gcc44 (GCC) 4.4.4 can be installed through yum.
FreeBSD 9.0 comes with gcc (gcc) 4.2.1. you can install GCC 4.6 through ports (currently 4.6.2)
We use C ++ to write a very simple C ++ program:
Int main (){
Return 0;
}
Then compile with g ++:
# G ++ 44 main. cpp-o main
Run ldd to view the output result in Linux:
Libstdc ++. so.6 =>/usr/lib64/libstdc ++. so.6 (0x000000336f000000)
Libm. so.6 =>/lib64/libm. so.6 (0x000000336cc00000)
Libgcc_s.so.1 =>/lib64/libgcc_s.so.1 (0x000000336e400000)
Libc. so.6 =>/lib64/libc. so.6 (0x000000336c400000)
/Lib64/ld-linux-x86-64.so.2 (0x000000336c000000)
The output result of FreeBSD is:
Libstdc ++. so.6 =>/usr/lib/libstdc ++. so.6 (0 × 800849000)
Libm. so.5 =>/lib/libm. so.5 (0x800b59000)
Libgcc_s.so.1 =>/lib/libgcc_s.so.1 (0x800d7a000)
Libc. so.7 =>/lib/libc. so.7 (0x800f87000)
Two lines are marked red. Because they are from gcc. So there is a question: are these two libraries the same for gcc of different versions? Or do I have the same C ++ standard library (libstdc ++. so) interfaces as gcc 4.4, gcc 4.6, gcc 4.2, and gcc 4.1? Is the implementation the same? (This refers to the part to be compiled, such as a non-template class)
Let's take a look at how CentOS works:
CentOS 5 gcc44-c ++ this package comes with only two so. /Usr/lib/gcc/x86_64-redhat-linux6E/4.4.4/32/libstdc ++. so and/usr/lib/gcc/x86_64-redhat-linux6E/4.4.4/libstdc ++. so. These two so files are actually text files, and the content is probably like this:
INPUT (-lstdc ++ _ nonshared/usr/lib64/libstdc ++. so.6)
That is, it will statically link to/usr/lib/gcc/x86_64-redhat-linux6E/4.4.4/libstdc ++ _ nonshared. a file and dynamically link to/usr/lib64/libstdc ++. so.6 (this file is provided by gcc 4.1)
Therefore, in CentOS 5, the gcc 4.4 compilation does not need to be installed in the runtime environment!
Then let's see how FreeBSD does it:
Install the so of gcc 4.6 in the/usr/local/lib/gcc46/directory. If you have installed it in a 64-bit environment, only the 64-bit version is available, but not the 32-bit version. The most important thing is that it is indeed an elf format of so, rather than text files, soft links or something.
If a file is compiled in FreeBSD as follows:
# G ++ 46-o t test. cpp
Then it will mistakenly link to so of 4.2
Libstdc ++. so.6 =>/usr/lib/libstdc ++. so.6 (0 × 800849000)
Libm. so.5 =>/lib/libm. so.5 (0x800b59000)
Libgcc_s.so.1 =>/lib/libgcc_s.so.1 (0x800d7a000)
Libc. so.7 =>/lib/libc. so.7 (0x800f87000)
If your program can still work normally, it depends on Destiny. The correct method is to add-Wl,-rpath =/usr/local/lib/gcc46 to the link.
A document on FreeBSD's official website explains this problem: Ghost.
If you only want ports to use gcc 4.6, simply add "USE_GCC = 4.6" to/etc/make. conf.
,
Author snnn