I compiled a static library. I have two files.
mylib_1.cwith functionfoo1in itmylib_2.cwith functionfoo2in it.
Both #include "mylib.h".
I compiled a library like so:
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
Then I tried to compile mylib_test.c with my library.
#include "mylib.h"
int main(void)
{
foo1("do something cool");
foo2("do something cool");
return 0;
}
If I compile like gcc mylib_test.c mylib.a, GCC succeeds and everything works fine.
If I compile like gcc mylib_test.c -Lmylib.a, GCC fails with:
C:\path\to\mylib_test.c:x: undefined reference to foo1
C:\path\to\mylib_test.c:x: undefined reference to foo2
Why does GCC fail?
If it makes a difference, I'm running the latest version of MinGW on Windows 7.1.