Using gcc under linux some time ago in some simple c program compile time,
ecco shoes on sale, gcc-Wall NAME.c-o NAME (c because the program in some number of libraries) always prompt I did not define 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,
ecco shoes online, which contains the ANSI / ISO C standard specified function,
ecco boot, 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: ~ $ [ ,],
ecco shoes sale,[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, the compiler will not link to 'libm.a'.
sqrt to make the compiler can be linked into the main program 'math.c',
ecco golf shoes, 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, such as sin, cos, 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,
ecco online, 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 * /