Differences between Linux and FreeBSD when using non-system built-in gcc
Source: Internet
Author: User
The following is a comparison between CentOS5 and FreeBSD9.0: the gcc that comes with CentOS5 is gcc (GCC) 4.1.2. you can use yum to install gcc44 (GCC) 4.4.4FreeBSD9.0 with gcc 4.2.1, you can install gcc4.6 through ports (currently 4. 6 .... 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.