(这真的属于这里吗)?
示例:使用数学库。使用首选编辑器创建此文件:
#include <stdio.h>
#include <math.h> //this declare the math library
int main() {
printf("%f\n", sin(1.0)); // using math and stdio library
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后你编译:
gcc -o test test.c -lm -lc
Run Code Online (Sandbox Code Playgroud)
阅读:编译test.c为test使用库libc和调用的可执行文件libm(注意:您不需要显式使用,-lc -lm因为它们在需要时默认链接;这只是一个示例——您必须明确告诉其他库)。
运行:
[romano:~/tmp] % ./test
0.841471
Run Code Online (Sandbox Code Playgroud)
瞧。
您可以使用手册页的第 3 部分获取图书馆的信息;例如
man 3 sin:
Run Code Online (Sandbox Code Playgroud)SIN(3) Linux Programmer's Manual SIN(3) NAME sin, sinf, sinl - sine function SYNOPSIS #include <math.h> double sin(double x);[...]
等等。
| 归档时间: |
|
| 查看次数: |
801 次 |
| 最近记录: |