Sto facendo funzionare un semplice Makefile senza problemi:Makefile regola C sottodirectory per rendere obj
CC=gcc
CFLAGS= -std=c99 -ggdb -Wall -I.
DEPS = hellomake.h
OBJ = hellomake.o hellofunc.o
%.o: %.c $(DEPS)
$(CC) -c -o [email protected] $< $(CFLAGS)
hellomake: $(OBJ)
gcc -o [email protected] $^ $(CFLAGS)
I file sono nella directory del progetto principale:
./project/Makefile
./project/hellomake.c
./project/hellomake.h
poi ho cercato di file organizzati , e mettere le cose come:
./project/Makefile
./project/src/hellomake.c
./project/include/hellomake.h
ed extra sottodirectory directory:
012../project/lib
./project/obj
Poi la nuova versione del Makefile:
IDIR =include
CC=gcc
CFLAGS= -std=c99 -ggdb -Wall -I$(IDIR)
ODIR=obj
LDIR =lib
LIBS=-lm
_DEPS = hellomake.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = hellomake.o hellofunc.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: %.c $(DEPS)
$(CC) -c -o [email protected] $< $(CFLAGS)
hellomake: $(OBJ)
gcc -o [email protected] $^ $(CFLAGS) $(LIBS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
sto la compilazione su Linux usando Emacs con il compilatore gcc:
$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Poi, corro su Emacs:
<Esc>
x
compile
make
E dà il messaggio:
"./project/src/" -*-
make: *** No rule to make target `obj/hellomake.o', needed by `hellomake'. Stop.
Compilation exited abnormally with code 2 at Wed Oct 3 17:10:01
Quale regola deve mancare per essere inclusa nel file Makefile?
Tutti i commenti e suggerimenti sono molto apprezzati.
Grazie per il tuo suggerimento, è stato aggiunto al codice. Quindi il compilatore si lamenta:
make -k
make: *** No rule to make target `src/hellomake.c', needed by `obj/hellomake.o'.
make: *** No rule to make target `../include/hellomake.h', needed by `obj/hellomake.o'.
make: Target `obj/hellomake.o' not remade because of errors
Qualche altro suggerimento?
Grazie in anticipo!
'project/obj' sarebbe un po 'più ragionevole di' project/src/obj' –
Ciao Steve-o. Grazie! Ho fatto il cambiamento che hai suggerito. – ThreaderSlash