对<函数名称>的未定义引用 [英] undefined reference to <function name>
本文介绍了对<函数名称>的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个简单的测试文件:
I have this simple test file:
#include "stack.h"
int main()
{
Stack* stck = init_stack();
return 0;
}
和 stack.h
定义如下:
and stack.h
is defined as follows:
#ifndef STACK_H
#define STACK_H
#define EMPTY_STACK -1
typedef struct stack
{
char ch;
struct stack* prev;
} Stack;
extern Stack* init_stack();
extern char pop(Stack*);
extern void push(Stack*, char);
#endif
这两个文件位于同一个目录中。但是,当我做 gcc ..
来构建它时,我总是得到下面的错误:
These two files are in the same directory. But when I do gcc ..
to build it, I keep getting the error below:
$ ls
stack.c stack.h teststack.c
$ gcc -o testit teststack.c
/tmp/ccdUD3B7.o: In function `main':
teststack.c:(.text+0xe): undefined reference to `init_stack'
collect2: ld returned 1 exit status
有谁能告诉我我在这里做错了什么?
Could anyone tell me what I did wrong here?
谢谢,
Thanks,
推荐答案
gcc -o testit teststack.c stack.c
您需要编译C源文件并链接目标文件;这可以在一个命令中完成。
You need to compile both C source files and link the object files; this does it all in one command.
这篇关于对<函数名称>的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文