gpt4 book ai didi

c++ - 目标 'Project1.exe' 的配方失败

转载 作者:太空狗 更新时间:2023-10-29 21:00:05 24 4
gpt4 key购买 nike

我尝试在 Dev-C++ 中编译一个简单的 c 文件,它在第 25 行显示错误C:\Users\varun\Desktop\cprog\Makefile.win 目标“Project1.exe”的配方失败。

生成文件.win

# Project: Project1
# Makefile created by Dev-C++ 5.6.2

CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = main.o Untitled2.o
LINKOBJ = main.o Untitled2.o
LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc
INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include"
CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++"
BIN = Project1.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm.exe -f

.PHONY: all all-before all-after clean clean-custom

all: all-before $(BIN) all-after

clean: clean-custom
${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
**$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)**

main.o: main.c
$(CC) -c main.c -o main.o $(CFLAGS)

Untitled2.o: Untitled2.c
$(CC) -c Untitled2.c -o Untitled2.o $(CFLAGS)

错误

C:\Users\varun\Desktop\cprog\Untitled2.o    Untitled2.c:(.text+0x0): multiple definition of `main'
C:\Users\varun\Desktop\cprog\main.o main.c:(.text+0x0): first defined here
C:\Users\varun\Desktop\cprog\collect2.exe [Error] ld returned 1 exit status
25 C:\Users\varun\Desktop\cprog\Makefile.win recipe for target 'Project1.exe' failed

最佳答案

输出的重要部分是:

C:\Users\varun\Desktop\cprog\Untitled2.o    Untitled2.c:(.text+0x0): multiple definition of `main'

它告诉你,你有两个函数定义 main .您在可执行文件中恰好需要一个这样的定义。错误的下一行告诉您该定义在哪里:

C:\Users\varun\Desktop\cprog\main.o main.c:(.text+0x0): first defined here

所以你有函数 mainUntitled2.c 中定义你还有另一个功能 mainmain.c 中定义.删除其中一个。从名字上看可能是main.c完全没有必要,但如果不看文件我就无法判断。

关于c++ - 目标 'Project1.exe' 的配方失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23084708/

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