gpt4 book ai didi

c - 对“[function]”的 undefined reference

转载 作者:行者123 更新时间:2023-11-30 21:05:13 25 4
gpt4 key购买 nike

编辑#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

该项目包含以下文件:

  1. B13-03_MAIN.h
  2. B13-03_MAIN.c
  3. B13-03_H1.h
  4. B13-03_F1.c

未定义的函数在 B13-03_MAIN.h 中声明,并在 B13-03_MAIN.c 中定义。两个应用程序文件都使用 B13-03_MAIN.h 作为原型(prototype)。

非常感谢您的帮助。

IDE Version

Tools

Plugins

最佳答案

该问题涉及未定义函数的错误嵌套。我重点关注 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 - 对“[function]”的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55687807/

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