编辑#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作为原型。
非常感谢您的帮助。
最佳答案
该问题涉及未定义函数的错误嵌套。我专注于B13-03_MAIN.h和B13-03_MAIN.c。
/* B13-03_MAIN.h */
create_article();
show_article();
edit_article();
delete_article();
有问题的实施:
/* B13-03_MAIN.c */
#include <stdio.h>
#include "B13-03_MAIN.h"
#include "B13-03_H1.h"
void main(void) {
switch(option) {
case abc_c: create_article(); break;
case abc_s: show_article(); break;
case abc_e: edit_article(); break;
case abc_d: delete_article(); break;
default: printf("Undefined option.");
}
void create_article(void) {
...
}
void show_article(void) {
...
}
void edit_article(void) {
...
}
void delete_article(void) {
...
}
} /* This curly braces is incorrectly nested */
没有问题的实施:
void main(void) {
switch(option) {
case abc_c: create_article(); break;
case abc_s: show_article(); break;
case abc_e: edit_article(); break;
case abc_d: delete_article(); break;
default: printf("Undefined option.");
}
} /*Incorrectly nested curly brace should be implemented here */
void create_article(void) {
...
}
void show_article(void) {
...
}
void edit_article(void) {
...
}
void delete_article(void) {
...
}
关于c - 未定义对“[功能]”的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55687807/