假设我有三个C源代码文件。前两个是库文件(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-implib=libre.a (对于re.c) cc -o test.dll test.c -L. -lre -shared -Wl,--out-implib=libtest.a (对于test.c) cc -o main.exe main.c -L. -lre -ltest
那么如何在MinGW中创建等效的可在可执行二进制文件中静态链接的LIB,以及如何链接它们呢?
显然,在Windows下 :)