假设我有三个 C 源文件。前两个是 LIB (lib*.a?),第三个是使用它们的应用程序。
第一个是(re.c):
int re(int i) {
return i;
}
第二个是(test.c):
int re(int); // Depends on re.c
int test(int i) {
return re(i);
}
第三个是(main.c):
#include<stdio.h>
int test(int); // Uses test.c
int main(void) {
printf("%d\n",test(0));
return 0;
}
现在如何创建前两个 LIB,以便稍后将它们静态链接到主应用程序?
我知道如何创建 DLL 并在我的应用程序中动态链接它们,例如:
cc -o re.dll re.c -shared -Wl,--out-imlib=libre.a (for re.c)
cc -o test.dll test.c -L。-lre -shared -Wl,--out-implib=libtest.a (for test.c)
cc -o main.exe main.c -L。-lre -ltest
那么如何创建等效的 LIB 以在 MinGW 中的可执行二进制文件中静态链接,以及如何链接它们?
显然,在 Windows 下:)