我尝试在Dev-C++
中编译一个简单的c文件,它在第25行显示错误
C:\Users\varun\Desktop\cprog\Makefile.win recipe for target 'Project1.exe' failed.
Makefile.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
答案 0 :(得分:4)
输出的重要部分是:
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
因此,main
中定义了函数Untitled2.c
,并且您在main
中定义了另一个函数main.c
。删除其中一个。从名称来看,main.c
可能完全不必要,但我看不到文件就无法分辨。