| Back to logs list
53976 2010 年 03 月 23 日 13:36 Reading (loading. ..) Comments (0) Category: MSN-personal diary using gcc under linux some time ago in some simple c program compile time,
The nature of value investors - Qzone log,
UGG Classic Mini, gcc-Wall NAME.c-o NAME (c because the program in some number of libraries) is always I did not suggest the definition of it. Le long time on the network to find the answer to all unsolved. `Le `` is finally get the following:
# link external libraries. Library is pre-compiled object files (object
files) collection, they can be linked into the program. Static library to the suffix '. A' special archive file (archive file) storage. Standard system libraries can be in the directory
/ usr / lib and / lib find. For example, Unix systems in the class math library in C language, generally stored as a file
/ usr / lib / libm.a. The library function prototype declarations in the header file / usr / include / math.h in. C standard library itself is stored as
/ usr / lib / libc.a,
UGG Classic Cardy, which contains the ANSI / ISO C standard specified function, such as the 'printf'. C is for each program,
Thousand years of Chinese Zodiac and marriage with - Qzone log, libc.a
be linked by default.
The following is a call to math library libm.a sqrt function in the example:
[email = hua @ hua-linux: ~ $] hua @ hua-linux: ~ $ [ ,],[3 int main (void)
4 {
5 double x = sqrt (4.0);
6 printf (\}
[email = hua @ hua-linux: ~ $] hua @ hua-linux :~$[/ email] gcc-Wall math.c / usr / lib / libm.a-o ; math
[email = hua @ hua-linux: ~ $] hua @ hua-linux :~$[/ email]. / math
The value of sqrt (4.0) is ; 2.000000
# If you do not add / usr / lib / libm.a will complain,
UGG ブーツ, suggesting that there is no definition of sqrt
because the function sqrt, are not defined in this program is not in the default library 'libc.a' in; unless it is specified, the compiler will not link to 'libm.a'.
sqrt to make the compiler can be linked into the main program 'math.c', we need to provide math libraries 'libm.a'. Easy to think of a more troublesome practice, but the command line to specify it explicitly, that is as above.
library 'libm.a' contains all the mathematical functions of the target file,
Re-bleeding - Qzone log,
UGG ムートンブーツ, such as sin, cos,
UGG クラシックミニ, exp, log and sqrt. Linker will search all the files to find the target file that contains sqrt.
Once the object file containing sqrt been found, the main program can be linked, a complete executable file can be generated.
executable file contains machine code and the main city library Xu ' libm.a 'in the machine code corresponding to sqrt.
order to avoid the command line, specify the long path, the compiler to provide a quick link library option '-l'. For example, the following command
code:
$ gcc-Wall math.c-lm-o math / * with gcc-Wall math.c-lm -o math is the kind of effect * /