Cygwin - Makefile-error:目标`main.o'的配方失败 [英] Cygwin - Makefile-error: recipe for target `main.o' failed

查看:1255
本文介绍了Cygwin - Makefile-error:目标`main.o'的配方失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前没有写一个好的makefile,不知道为什么..-.-



这是我的main.c:

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

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

这是我的makefile:

 #make SYSTEM = OS = ENVIRONMENT = 
#要使用的二进制文件
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 ++ - 转储; 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 ,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 ==标准构建:make SYSTEM = I686 OS = WIN32 ENVIRONMENT = MINGW
@ echo
@echo
make SYSTEM = I686 OS = WIN32 ENVIRONMENT = MINGW gyro

############# #########################################
#隐含规则和文件名extensions ...
.SUFFIXES:.h .o .c

.co:%.h
@echo编译$< for $(SYSTEM)$(OS)$(ENVIRONMENT)...
@echo MEEP
$(CXX)$(CFLAGS)$(INCLUDES)-c $& -o $ @
@echo MEEP2

############################### ##############################
#目标规则
gyro:$(OBJS)
@echo构建软件$(SYSTEM)...
@echo
$(CXX)$(CFLAGS)$(LFLAGS)-o $ @ $(EXE)$(OBJS)$(LIBRARIES )

################################################ ####################
#Clean
.PHONY:clean
clean:
$(REMOVE)$ OBJS)


########################################### #########################
#Info
.PHONY:info
info:
@ echo
@echo关于C ++编译器/链接器的信息:
@echo
$(INFO_CXX)

当我输入make gyro,
i接收输出:

 编译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:目标`main.o'的配方失败
make:*** [main.o]错误1

但行号83位于.co:%.h后面。我不明白为什么。
有人有我的解决方案吗?

解决方案

您会看到 -D c $ c> g ++ 命令行?它们导致了问题。您必须 -D 项目中 -DWIN32



如果您坚持使用类似-D $(SYSTEM)-D $(ENVIRONMENT ),那么你可以使用类似:

  SYSTEM?= generic 
ENVIRONMENT?= generic



在makefile中给出它们的默认值。



缺少所有重要的输出:

 <命令行>:0:1:错误:宏名称必须是标识符
< command-line>:0:1:error:宏名称必须是标识符

-D -DWindows_NT ,即定义一个名为的预处理器宏, code> -DWindows_NT ;它当然不是有效的标识符(类似于 -D -I。


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?

解决方案

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.)

这篇关于Cygwin - Makefile-error:目标`main.o'的配方失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆