Cygwin - 生成文件错误 : recipe for target `main.o' failed

标签 c makefile cygwin

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

这是我的 main.c:

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

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

这是我的生成文件:

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

当我输入 make gyro 时, 我收到输出:

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

但是第 83 行在 .c.o 后面:%.h。我不明白为什么。 有人能帮我解决吗?

最佳答案

您在 g++ 命令行中看到两个空的 -D 条目了吗?他们造成了问题。您必须-D 项中有值,例如-DWIN32

如果你坚持使用像 -D$(SYSTEM) -D$(ENVIRONMENT) 这样的东西,那么你可以使用像这样的东西:

SYSTEM ?= generic
ENVIRONMENT ?= generic

在为它们提供默认值的 makefile 中。

您的输出看起来缺少所有重要的输出:

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

澄清一下,实际上发送到 g++ 的是 -D -DWindows_NT,即定义一个名为 -DWindows_NT 的预处理器宏;这当然不是有效标识符(对于 -D -I. 也是如此)

关于Cygwin - 生成文件错误 : recipe for target `main.o' failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11932809/

相关文章:

linux - "make install"- 更改所有构建的输出目标

linux - 使用make构建后的.d文件是什么

Python 2.7 未在 Cygwin 中加载

cygwin - 在 Cygwin 中运行 XWindow 程序

c - 尝试从数组中打印出网格,但实际上没有显示任何内容

c - 数组地址操作

c - 使用 mem alloc 通过指针或指向指针的指针将字符串数组发送到函数?

c - 在 C 中使用链表实现堆栈时出错

boost - 在 Red Hat Linux 上安装 mapnik 失败

python - 属性错误: 'module' object has no attribute 'Firefox'