[c] Cygwin - Makefile-error: recipe for target `main.o' failed

I am currently failing to write a good makefile and don't know the reason why.. -.-

This is my main.c:

#include <windows.h>
#include <stdio.h>

int main(int argc, char *argv[])
{ 
   printf("MEEEEEP");
   return (0);
}

This is my 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)

When i type in make gyro, i receive the 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

But Line number 83 is behind .c.o: %.h. And i don’t understand why. Does anyone have a solution for me?

This question is related to c makefile cygwin

The answer is


You see the two empty -D entries in the g++ command line? They're causing the problem. You must have values in the -D items e.g. -DWIN32

if you're insistent on using something like -D$(SYSTEM) -D$(ENVIRONMENT) then you can use something like:

SYSTEM ?= generic
ENVIRONMENT ?= generic

in the makefile which gives them default values.

Your output looks to be missing the all important output:

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

just to clarify, what actually got sent to g++ was -D -DWindows_NT, i.e. define a preprocessor macro called -DWindows_NT; which is of course not a valid identifier (similarly for -D -I.)


Examples related to c

conflicting types for 'outchar' Can't compile C program on a Mac after upgrade to Mojave Program to find largest and second largest number in array Prime numbers between 1 to 100 in C Programming Language In c, in bool, true == 1 and false == 0? How I can print to stderr in C? Visual Studio Code includePath "error: assignment to expression with array type error" when I assign a struct field (C) Compiling an application for use in highly radioactive environments How can you print multiple variables inside a string using printf?

Examples related to makefile

MINGW64 "make build" error: "bash: make: command not found" "No rule to make target 'install'"... But Makefile exists How to overcome "'aclocal-1.15' is missing on your system" warning? How to install and use "make" in Windows? How to get a shell environment variable in a makefile? Using local makefile for CLion instead of CMake Difference between using Makefile and CMake to compile the code How to set child process' environment variable in Makefile Windows 7 - 'make' is not recognized as an internal or external command, operable program or batch file Debugging the error "gcc: error: x86_64-linux-gnu-gcc: No such file or directory"

Examples related to cygwin

How to install MinGW-w64 and MSYS2? Split text file into smaller multiple text file using command line fatal: early EOF fatal: index-pack failed Git Extensions: Win32 error 487: Couldn't reserve space for cygwin's heap, Win32 error 0 How to cd into a directory with space in the name? Git push hangs when pushing to Github? Running a shell script through Cygwin on Windows Running Git through Cygwin from Windows .ssh directory not being created Cygwin - Makefile-error: recipe for target `main.o' failed