I have 2 projects.
The first has 4 files in it:
1. main.c (which include PNM.h)
2. PNM.c (which include PNM.h)
3. PNM.h
4. makefile
CC=gcc
LD=gcc
CFLAGS=--std=c99 -Wall -W -Wmissing-prototypes
LDFLAGS=
DOXYGEN=doxygen
RM=rm
AR=ar
RANLIB=ranlib
all: pnm
lib: PNM.o
@$(AR) ru libpnm.a PNM.o
@$(RANLIB) libpnm.a
pnm: main.o PNM.o
@$(LD) -o $@ $^ $(LDFLAGS)
main.o: main.c PNM.h
@$(CC) -o $@ -c main.c $(CFLAGS)
PNM.o: PNM.c PNM.h
@$(CC) -o $@ -c PNM.c $(CFLAGS)
clean:
@$(RM) -rf *.o
allclean: clean
@$(RM) -rf pnm
@$(RM) -rf libpnm.a
This project work perfectly.
In my second project, I have 6 files and libpnm.a:
1. libpnm.a
2. main.c (which include matricules.h)
3. matricules.c (which include matricules.h and codebarre.h)
4. matricules.h
5. codebarre.c (hich include codebarre.h and PNM.h)
6. codebarre.h
7. makefile
CC=gcc
LD=gcc
CFLAGS=--std=c99 -Wall -W -Wmissing-prototypes
LDFLAGS=
DOXYGEN=doxygen
RM=rm
all: codebarre
codebarre: main.o matricules.o codebarre.o libpnm.a
@$(LD) -o $@ $^ $(LDFLAGS)
main.o: main.c matricules.h
@$(CC) -o $@ -c main.c $(CFLAGS)
matricules.o: matricules.c matricules.h codebarre.h
@$(CC) -o $@ -c matricules.c $(CFLAGS)
codebarre.o: codebarre.c codebarre.h
@$(CC) -o $@ -c codebarre.c $(CFLAGS)
clean:
@$(RM) -rf *.o
allclean: clean
@$(RM) -rf codebarre
(each project is in a separated folder)
when I use
make
I get an error:
codebarre.c:6:17: fatal error: PNM.h: No such file or directory
#include "PNM.h"
^
compilation terminated.
same error when I use
make codebarre.o
I think I don't use my library correctly. But I don't know how to.
edit: added PNM.h in the directory -> work well