未定义的引用'[function]'

问题描述 投票:-3回答:1

编辑#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. Bi1303h1h
  4. B13-03_F1.c

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

非常感谢任何帮助。

IDE Version

Tools

Plugins

c modular
1个回答
0
投票

该问题涉及未定义函数的不正确嵌套。我专注于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) {
...
}
© www.soinside.com 2019 - 2024. All rights reserved.