I have a header file myheader.h and a static library libmylib.a file in directory1. In directory2, I'm writing a program which uses them. Suppose I have main.c in directory2 which uses myheader.h and libmylib.a. How do I create a Makefile to compile and link them?
Right now, in my main.c, I have added
#include "../directory1/myheader.h"
Here's my Makefile at the moment:
CC = gcc
INCLUDES = -I
CFLAGS = -g -Wall $(INCLUDES)
main: main.o ../directory1/libmylib.a
$(CC) main.o ../directory1/libmylib.a -o main
main.o: main.c ../directory1/myheader.h
$(CC) $(CFLAGS) -c main.c
I'm getting the following warning:
gcc -g -Wall -I -c main.c
/home/me/directory2/main.c:72: undefined reference to `foo'
collect2: ld returned 1 exit status
make: *** [main.o] Error 1
where foo is one of the functions in the library.