roisn 发表于 2022-6-24 04:40:44

vscode里C语言多文件编程debug弹出error -1


vscode里debug源文件的时候不仅自动把我放在同一个文件夹里的exe文件给删除了,而且弹出了这个

> Executing task: C/C++: gcc.exe 生成活动文件 <

正在启动生成...
E:\msys2\mingw64\bin\gcc.exe -fdiagnostics-color=always -g C:\Users\wyy\Desktop\summer\program\C_project\src\TarjanDFS.c -o C:\Users\wyy\Desktop\summer\program\C_project\src\TarjanDFS.exe
E:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\wyy\AppData\Local\Temp\cc3M2Y92.o: in function `Tarjan':
C:/Users/wyy/Desktop/summer/program/C_project/src/TarjanDFS.c:19: undefined reference to `CreateStack'
E:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/wyy/Desktop/summer/program/C_project/src/TarjanDFS.c:21: undefined reference to `push'
E:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/wyy/Desktop/summer/program/C_project/src/TarjanDFS.c:51: undefined reference to `pop'
E:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\wyy\AppData\Local\Temp\cc3M2Y92.o: in function `main':
C:/Users/wyy/Desktop/summer/program/C_project/src/TarjanDFS.c:69: undefined reference to `CreateDirGraph'

collect2.exe: error: ld returned 1 exit status
生成已完成,但出现错误。
The terminal process terminated with exit code: -1.


exe 文件由makefile生成的,这里是makefile配置
#
# 'make'      build executable file 'main'
# 'make clean'removes all .o and executable files
#

# define the C compiler to use
CC = gcc

# define any compile-time flags
CFLAGS        := -Wall -Wextra -g

# define library paths in addition to /usr/lib
#   if I wanted to include libraries not in /usr/lib I'd specify
#   their path using -Lpath, something like:
LFLAGS =

# define output directory
OUTPUT        := C:\Users\wyy\Desktop\summer\program\C_project

# define source directory
SRC                := src

# define include directory
INCLUDE        := include

# define lib directory
LIB                := lib

ifeq ($(OS),Windows_NT)
MAIN        := TarjanDFS.exe
SOURCEDIRS        := $(SRC)
INCLUDEDIRS        := $(INCLUDE)
LIBDIRS                := $(LIB)
FIXPATH = $(subst /,\,$1)
RM                        := del /q /f
MD        := mkdir
else
MAIN        := TarjanDFS
SOURCEDIRS        := $(shell find $(SRC) -type d)
INCLUDEDIRS        := $(shell find $(INCLUDE) -type d)
LIBDIRS                := $(shell find $(LIB) -type d)
FIXPATH = $1
RM = rm -f
MD        := mkdir -p
endif

# define any directories containing header files other than /usr/include
INCLUDES        := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))

# define the C libs
LIBS                := $(patsubst %,-L%, $(LIBDIRS:%/=%))

# define the C source files
SOURCES                := $(wildcard $(patsubst %,%/*.c, $(SOURCEDIRS)))

# define the C object files
OBJECTS                := $(SOURCES:.c=.o)

#
# The following part of the makefile is generic; it can be used to
# build any executable just by changing the definitions above and by
# deleting dependencies appended to the file from 'make depend'
#

OUTPUTMAIN        := $(call FIXPATH,$(OUTPUT)/$(MAIN))

all: $(OUTPUT) $(MAIN)
        @echo Executing 'all' complete!

$(OUTPUT):
        $(MD) $(OUTPUT)

$(MAIN): $(OBJECTS)
        $(CC) $(CFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(OBJECTS) $(LFLAGS) $(LIBS)

# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
# (see the gnu make manual section about automatic variables)
.c.o:
        $(CC) $(CFLAGS) $(INCLUDES) -c $<-o $@

.PHONY: clean
clean:
        $(RM) $(OUTPUTMAIN)
        $(RM) $(call FIXPATH,$(OBJECTS))
        @echo Cleanup complete!

run: all
        ./$(OUTPUTMAIN)
        @echo Executing 'run: all' complete!





谢谢各位相助啊

jackz007 发表于 2022-6-24 09:15:17

      错误原因是,被调用的函数 “CreateStack()” 未定义。

人造人 发表于 2022-6-24 09:29:19

in function `Tarjan':
    undefined reference to `CreateStack'
TarjanDFS.c:21: undefined reference to `push'
TarjanDFS.c:51: undefined reference to `pop'
in function `main':
    TarjanDFS.c:69: undefined reference to `CreateDirGraph'

这报错信息都告诉你了,你就是不看

roisn 发表于 2022-6-26 04:13:41

那好像是个bug真的不是我的锅
页: [1]
查看完整版本: vscode里C语言多文件编程debug弹出error -1