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

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

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

This is my main.c:

#include  #include   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 $

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?

回答1:

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:

:0:1: error: macro names must be identifiers :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.)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!