Several questions about programming and compiling programs in Linux
Source: Internet
Author: User
For more information about how to compile and compile programs in Linux-Linux general technology-Linux programming and kernel, see the following. How to compile a program in Linux?
Most Linux programs are compiled in C language and compiled by gnu c. Currently, GCC is part of various release kits. For the latest GCC compiler versions, articles, and patches, see ftp://ftp.gnu.org/pub/gnu /.
Programs compiled by C ++ must be compiled by gnu c ++. gnu c ++ is also part of various release kits. The latest versions and patches are also available on the above websites.
Compiling the 2.0.x kernel requires the GCC version 2.7.2.x. Using a compiler such as GCC 2.8.x, EGCS, or PGCC may cause unexpected consequences.
How to port other Unix programs to Linux?
In general, Unix programs do not need to be changed. They can be transplanted to Linux simply as prompted. If an error message occurs during installation, you do not know how to handle it, you can guess or skip it, but such programs often have bugs. So it is best to ask experienced people.
If you want to port the program from BSD-ish, add-I/usr/include/bsd and? Lbsd command.
What is ld. so? Where can I find it?
Ld. so is the dynamic function library loader. In the past, the program using the shared function library used about 3 K space at the beginning of the original code to find and load the shared function library. Now, this code is added with a special shared function library/lib/ld. so, all programs can use this shared library, which saves disk space and facilitates upgrade.
Ld. so you can obtain tsx-11.mit.edu/pub/linux/packages/gcc/from the following URL /.
How can I upgrade library functions without causing system crash?
Note: this operation should develop the habit of backing up, because this operation is prone to errors.
If you upgrade an old function library like libc4, this process will become very difficult. And you should make libc4 and libc5 coexist on the system, because some old programs still need it. Upgrade libc5.
The problem of upgrading a dynamic library often occurs when you remove the old function library, and the program used for upgrading cannot run. There are many ways to solve this problem. One method is to temporarily back up the function libraries required to run the program. They are generally in/lib/,/usr/lib/,/usr/local/lib/, or other places, in the file/etc/ld. so. the conf file contains detailed records.
For example, when you upgrade libc5, the directory/lib/contains the following files:
Libc. so.5
Libc. so.5.4.33
Libm. so.5
Libm. so.5.0.9
These are C function libraries and math libraries. Copy them to other directories contained in the file/etc/ld. so. conf, such as/usr/lib:
Cp-df/lib/libc. so.5 */usr/lib/
Cp-df/lib/libm. so.5 */usr/lib/
Ldconfig
Remember to run ldconfig to upgrade the configuration file of the function library.
File libc. so.5 and libm. so.5 is the link file of the actual library file. When you upgrade it, if the old link file exists, the new link will not be generated unless you use the-f option of the CP command. The-d option of CP only copies the linked file and does not copy the original file.
If you need to directly overwrite the link, use the ln Command Option-f.
For example, copy a new library function to overwrite the old one. Create a link to the new function library and copy the function library and link to/lib/. The command is as follows:
Ln-sf./libm. so.5.0.48 libm. so.5
Ln-sf./libc. so.5.0.48 libc. so.5
Cp-df libm. so.5 */lib
Cp-df libc. so.5 */lib
Once copied, do not forget to run ldconfig.
If everything goes well, you can delete the backup of the old function library.
Can I use the code or compiler compiled on 486 with 386?
Of course, unless you compile the kernel.
The option that GCC uses to compile on 486-mruntime only optimizes the compiled program and makes it run faster. These compiled programs can still run well on 386, but the effect is poor.
However, from kernel 1.3.35 and later, kernels compiled with the 486 or Pentium option cannot be used on machines with 386.
GCC can be configured for 386 and 486. The difference between the two is that GCC configured for 386 uses-m386 as the default option, while GCC configured for 486 uses-m386 as the default option.
What can gcc-O6 do?
Currently, it has the same functions as-O2 (GCC 2.5) or-O3 (GCC 2.6, 2.7), and all versions have the same functions. New kernel Makefiles use-O2, so you should also use-O2.
What is linux/*. h and asm/*. h?
The directory/usr/include/linux/and/usr/include/asm/low files are soft links to the kernel header file, the kernel header file is actually in the directory/usr/src/kernel */down.
How to create a shared function library?
For ELF, the command is as follows:
Gcc-fPIC-c *. c
Gcc-shared-Wl,-soname, libfoo. so.1-o libfoo. so.1.0 *. o
For a. out, download n.nn.tar.gz from the http://tsx-11.mit.edu/pub/linux/packages/GCC/src/, which contains detailed instructions. We recommend that you upgrade the shared library from a. out To ELF.
Why is my compiled executable program very large?
The most likely reason for generating executable programs using the ELF compiler is that there is no suitable. so library to link to your library function. Each function library like libc. so.5.2.18 should have a link like libc. so.
Using the. out compiler, it is possible that the-g option is used to generate a large executable program. This will generate a static link library instead of a dynamic link library.
Where can we get the 'lint' for Linux '?
Most of the 'lint' functions have been built into GCC. Opening the-Wall option of GCC opens many useful external warnings.
There is also a software function called 'lclint' that is similar to the traditional lint, the original code can be found in the http://larch.lcs.mit.edu // pub/Larch/lclint.
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.