【发布时间】:2019-09-05 08:30:24
【问题描述】:
编辑 #1:请在使用代码示例时找到解决方案作为此初始帖子的答案。也请尝试在What is an undefined reference/unresolved external symbol error and how do I fix it? 中找到可能的解决方案它对我没有帮助,但也许它适合你。
我尝试构建一个由每两个头文件和应用程序文件组成的项目。如果我编译每个文件,则不会发生错误。如果我构建项目,我会遇到以下错误。
cd 'D:\Master\M_32561\9000_A\B13-03'
P:\PortableApps\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/P/PortableApps/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/d/Master/M_32561/9000_A/B13-03'
"/P/PortableApps/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/b13-03.exe
make.exe[2]: Entering directory `/d/Master/M_32561/9000_A/B13-03'
mkdir -p dist/Debug/MinGW-Windows
gcc -o dist/Debug/MinGW-Windows/b13-03 build/Debug/MinGW-Windows/B13-03_F1.o build/Debug/MinGW-Windows/B13-03_MAIN.o
build/Debug/MinGW-Windows/B13-03_F1.o: In function `anzeigen_artikelbestand':
D:\Master\M_32561\9000_A\B13-03/B13-03_F1.c:283: undefined reference to `ausgeben_artikelbestand_mit_listenkopf'
build/Debug/MinGW-Windows/B13-03_MAIN.o: In function `main':
D:\Master\M_32561\9000_A\B13-03/B13-03_MAIN.c:39: undefined reference to `erfassen_artikel'
D:\Master\M_32561\9000_A\B13-03/B13-03_MAIN.c:42: undefined reference to `anzeigen_artikel'
D:\Master\M_32561\9000_A\B13-03/B13-03_MAIN.c:45: undefined reference to `aendern_artikel'
D:\Master\M_32561\9000_A\B13-03/B13-03_MAIN.c:48: undefined reference to `loeschen_artikel'
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/b13-03.exe] Error 1
make.exe[2]: Leaving directory `/d/Master/M_32561/9000_A/B13-03'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/d/Master/M_32561/9000_A/B13-03'
make.exe": *** [.build-impl] Error 2
该项目由以下文件组成:
- B13-03_MAIN.h
- B13-03_MAIN.c
- B13-03_H1.h
- B13-03_F1.c
未定义的函数在 B13-03_MAIN.h 中声明并在 B13-03_MAIN.c 中定义。两个应用程序文件都使用 B13-03_MAIN。h 作为原型。
非常感谢您的帮助。
【问题讨论】:
-
提到的未定义的函数,那些定义(实现)的函数在哪里?他们来自图书馆吗?从您创建的某个源文件?从您应该创建的源文件?
-
@Someprogrammerdude 这些函数在 B13-03_MAIN.h 中声明为 B13-03_MAIN.c 和 B13-03_F1.c 中的原型,并在 B13-03_MAIN.c 中定义。它们不是来自图书馆。它们来自前面提到的源文件。属于该示例的所有源文件均已创建。
-
您可以尝试创建一个minimal reproducible example 来展示给我们看吗?不作为链接!链接可能会消失或其内容发生变化,从而使问题变得毫无价值(请记住,此站点不仅可以帮助您现在,还可以帮助将来遇到类似问题的其他人)。请尽量使问题自成一体。也请阅读how to ask good questions,以及this question checklist。
-
@Someprogrammerdude 我也尝试创建一个示例来帮助其他人,当然在问题解决之后将重点放在重要部分。我会在我最初的帖子中做到这一点。我在问自己为什么在我目前正在编辑它时,我看不到在我的初始帖子中上传图片的选项。这就是我使用链接的原因,是的,在帮助他人之前首先帮助我。上传附件以提供完整代码会很有帮助,但是很遗憾,这方面不支持。