| 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, 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,
ugg australia 激安,
Began to understand the.! - Qzone log, 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, which contains the ANSI / ISO C standard specified function, such as the 'printf'. C is for each program, 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: ~ $ [ ,],
UGG オーストラリア,[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, 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,
UGG Classic Mini, 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,
Do not see you lose out haha! - Qzone log, but the command line to specify it explicitly, that is as above.
library 'libm.a' contains all the mathematical functions of the target file, such as sin,
Letter - Qzone log, cos,
UGG Classic Cardy, exp,
UGG Classic Tall, 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 * /