DEA*_*EEF 3 c gcc static-libraries unix-ar .a
我编译了一个静态库.我有两个文件.
mylib_1.c功能foo1于其中mylib_2.c功能foo2于其中.两者#include "mylib.h".
我编译了一个像这样的库:
gcc -c mylib_1.c -o mylib_1.o
gcc -c mylib_2.c -o mylib_2.o
ar cr mylib.a mylib_1.o mylib_2.o
Run Code Online (Sandbox Code Playgroud)
然后我尝试mylib_test.c用我的库编译.
#include "mylib.h"
int main(void)
{
foo1("do something cool");
foo2("do something cool");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我编译得像gcc mylib_test.c mylib.a,GCC成功,一切正常.
如果我编译得像gcc mylib_test.c -Lmylib.a,GCC失败了:
C:\path\to\mylib_test.c:x: undefined reference to foo1
C:\path\to\mylib_test.c:x: undefined reference to foo2
Run Code Online (Sandbox Code Playgroud)
GCC为什么失败?
如果它有所不同,我在Windows 7.1上运行最新版本的MinGW.