gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:03:41 26 4
gpt4 key购买 nike

我目前没能写出一个好的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com