我有以下文件:体系结构x86_64的未定义符号。如何正确包含?
bst.h:其中只包含声明
typedef struct Node Node;
struct Node {
unsigned int key;
Node *left;
Node *right;
};
int insert(Node *node);
Node* lookup(unsigned int key);
int delete(Node *node);
bst.c:它定义了声明
#include "bst.h"
#include <stdio.h>
Node *root = NULL;
int insert(Node* node) {
... implementation ...
return 0;
}
Node* lookup(unsigned int key) {
... implementation ...
return current;
}
int delete(Node *node) {
... implementation ...
return 0;
}
test_bst。 c:测试BST实施
#include "bst.h"
#include <stdio.h>
int main() {
Node node = {10,NULL,NULL};
insert(&node);
return 0;
}
如果我运行gcc test_bst.c
我得到以下错误:
Undefined symbols for architecture x86_64:
"_insert", referenced from:
_main in cc1m0mA1.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
什么我错在这里做什么?它是否与我包含文件的方式有关?或者用我的汇编指令?我看到很多与我的标题相同的问题 - 但是,它们都不能帮助我解决我的错误。
你需要编译这两个C文件。 – teppic
将'extern'添加到头文件中的函数签名中。 –