链接和包含头文件的区别

difference between linking and including header file

这两个是等同还是不同(在什么意义上)?

myfile1.c

    #include <stdio.h>
    #include <math.h>

    //some code here which uses math library

并使用 gcc

正常编译
$gcc myfile1.c

myfile2.c

    #include <stdio.h>

    //some code here which uses math library

但使用以下语句编译它

$gcc myfile2.c -lm

刚刚写了一个程序来测试这个:

#include <stdio.h>
#include <math.h>

void main() {
    double f = 0.5;
    printf("%f", sqrt(f));
}

这两个命令都会生成 8432 字节的文件,这些文件在我的机器上是相同的。

所以我猜在这两种情况下,libm 是动态链接的,我想如果只找到一个存档文件 (.a),而不是典型的文件,库将被静态链接(.so) 共享库