Cygwin – Makefile-error: recept voor doel `main.o’ is mislukt

Het lukt me momenteel niet om een goede makefile te schrijven en weet niet waarom.. -.-

Dit is mijn hoofd.c:

#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{ 
   printf("MEEEEEP");
   return (0);
}

Dit is mijn makefile:

# make SYSTEM= OS= ENVIRONMENT=
# Binaries to use
ifeq ($(ENVIRONMENT),MINGW)
  CXX   = i686-pc-mingw32-g++
else
  CXX   = g++
endif
REMOVE  = rm -vf
RC      = windres
EXE     = .exe
#############################################################
# Info
ifeq ($(CXX),g++)
INFO_CXX = g++ -dumpversion; g++ -dumpmachine
endif
#############################################################
# Flags
DEBUG = -DDEBUG -g
OPTIMIZATION = -O2 #-Winline -finline-functions
CFLAGS = -Wall -Wextra -W -static $(DEBUG) $(OPTIMIZATION) -D$(SYSTEM) -D$(OS) -D$(ENVIRONMENT) $(PRGFLAGS)
ifeq ($(SYSTEM),I686)
  CFLAGS   += -m32
  ifeq ($(OS),WIN32)
    CFLAGS += -D_WIN32 
  endif
  ifeq ($(ENVIRONMENT),MINGW)
    CFLAGS += -fexceptions 
  endif
endif
 LFLAGS    = 
#############################################################
# Files
CFILES      = main.c
OBJS        = ${CFILES:.c=.o}
#############################################################
# Include
INCLUDES      = -I.
#############################################################
# Library
LIBRARIES     = 
#############################################################
# Targets
.PHONY: all
all:    
    @echo == Standard build: make SYSTEM=I686 OS=WIN32 ENVIRONMENT=MINGW
    @echo
    @echo 
    make SYSTEM=I686 OS=WIN32 ENVIRONMENT=MINGW gyro
#############################################################
# Implicit rules and filename extensions... 
.SUFFIXES: .h .o .c
.c.o:     %.h
      @echo Compiling $< for $(SYSTEM) $(OS) $(ENVIRONMENT) ...
      @echo MEEP
      $(CXX) $(CFLAGS) $(INCLUDES) -c $< -o $@
      @echo MEEP2
#############################################################
# Target rules
gyro: $(OBJS)
      @echo Building software for $(SYSTEM) ...
      @echo
      $(CXX) $(CFLAGS) $(LFLAGS) -o $@$(EXE) $(OBJS) $(LIBRARIES)
#############################################################
# Clean
.PHONY: clean
clean:
    $(REMOVE) $(OBJS)
#############################################################
# Info
.PHONY: info
info:
    @echo 
    @echo Information about C++ Compiler/Linker:
    @echo 
    $(INFO_CXX)

Wanneer ik typ in make gyro,
ik ontvang de output:

Compiling main.c for Windows_NT ...
MEEP
g++ -Wall -Wextra -W -static -DDEBUG -g -O2  -D -DWindows_NT -D  -I. -c main.c -o     main.o
makeNew.mak:83: recipe for target `main.o' failed
make: *** [main.o] Error 1

Maar Line nummer 83 achter .c.o:% .h. En ik begrijp niet waarom.
Heeft iemand een oplossing voor mij?


Antwoord 1, Autoriteit 100%

U ziet de twee lege -Dvermeldingen in de g++command line? Ze zijn het probleem veroorzaakt. U moet hebben waarden in het -Dartikelen bijv. -DWIN32

Als u aandringen op het gebruik van iets als -D $ (SYSTEM) -D $ (MILIEU), dan kun je zoiets als te gebruiken:

SYSTEM ?= generic
ENVIRONMENT ?= generic

in de makefile waardoor ze standaardwaarden.

Uw uitgang looks te ontbreken de alle belangrijke output:

<command-line>:0:1: error: macro names must be identifiers
<command-line>:0:1: error: macro names must be identifiers

Gewoon om te verduidelijken, wat er daadwerkelijk is verzonden naar g++was -D -DWindows_NT, d.w.z. definiëren een preprocessor macro genaamd -DWindows_NT; Dat is natuurlijk geen geldige identificatie (vergelijkbaar voor -D -I.)

Other episodes