2017-09-14 6 views
0

Je possède ce fichier C:Pourquoi ce fichier Makefile ne fonctionne-t-il pas?

// test.c 
#include <stdio.h> 

int main() 
{ 
    printf("Hello World!\n"); 
    return 0; 
} 

Et ce Makefile

OBJS=$(patsubst %.c,%.o,$(wildcard *.c)) 
EXEC=hello.exe 

all: $(EXEC) 

$(EXEC): $(OBJS) 

.PHONY: all 

Quand je fais make il ne crée pas mon objectif hello.exe pourquoi?

$ make 
cc -c -o hello.o hello.c 

Il n'a pas non plus travailler avec hello.exe:

$ make hello.exe 
make: Nothing to be done for 'hello.exe'. 

Et hello.exe n'existe pas:

$ ls hello.exe 
ls: cannot access 'hello.exe': No such file or directory 

J'utilise cette version de GNU Make

$ make --version 
GNU Make 4.2.1 
Built for x86_64-unknown-cygwin 
Copyright (C) 1988-2016 Free Software Foundation, Inc. 

EDIT

Cela fonctionne réellement quand je nomme mon exécutable le même de n'importe lequel de mes fichiers. Il fonctionne avec:

EXEC=hello 

Voir:

$ make 
cc -c -o hello.o hello.c 
cc hello.o -o hello 

Cela dit, je ne comprends pas pourquoi il ne fonctionne que de cette façon.

Répondre

2

La version avec hello.exe ne fonctionne pas parce que make n'a pas de règle implicite pour lui dire comment transformer un tas de *.o en un seul *.exe.

Mais il ne ont des règles implicites (au moins ceux spécifiés par Posix) pour mettre en hello.chello.o et lien dans hello. Souvenez-vous, Unix n'est pas DOS.

Oubliez le .exe lorsque vous utilisez Unix.