I am using MinGW on a Windows 8.1 machine and I'm trying to reference a static library. Try as I might I get an undefined reference error.
This is usually just a case of passing the -L
and -l
flags normally right but here is what I do...
I have the following directory structure:
myapp.c
mylib
mylib.c
mylib.h
mylib/mylib.c
#include <stdio.h>
void do_something_amazing(void) {
printf("Woah\n");
}
mylib/mylib.h
void do_something_amazing(void);
myapp.c
#include "mylib/mylib.h"
int main() {
do_something_amazing();
return (0);
}
I run the following commands to first create a libmylib
static library then to build the myapp
that references it:
gcc -c -o mylib/mylib.o mylib/mylib.c
ar rcs mylib/libmylib.a mylib/mylib.o
gcc -Lmylib -lmylib myapp.c
And the last finishes with this error:
cchqpYVl.o:myapp.c:(.text+0xc): undefined reference to `do_something_amazing'
collect2.exe: error: ld returned 1 exit status
This seems kind of basic, so I am sure I am being silly and I missed a step - any idea what I'm doing wrong?