简体   繁体   English

对avltree_init的未定义引用

[英]undefined reference to avltree_init

In code provided by instructor there is: 在讲师提供的代码中有:

typedef int (*avltree_cmp_fn_t)(const struct avltree_node *, const struct avltree_node *);

int avltree_init(struct avltree *tree, avltree_cmp_fn_t cmp, unsigned long flags);

After I define my_cmp function... 在定义my_cmp函数之后...

int my_cmp(const struct avltree_node *a, const struct avltree_node *b)
{
        struct my_struct *p = avltree_container_of(a, my_struct, node);
        struct my_struct *q = avltree_container_of(b, my_struct, node);
        return p->key - q->key;
}

and pass it as a parameter to avltree_init... 并将其作为参数传递给avltree_init ...

avltree_init(&tree, my_cmp, 0);

I get: 我得到:

undefined reference to `avltree_init(avltree*, int (*)(avltree_node const*, avltree_node const*), unsigned long)'

Could someone explain, please, why it happens and where did I make a mistake? 有人可以解释一下为什么会发生,我在哪里犯了错误? Thanks! 谢谢!

It seems from the error message that you're not linking with the file that contains the avltree_init function. 从错误消息看来,您没有与包含avltree_init函数的文件链接。 You need to link all files, including the file containing that function, to your final application. 您需要将所有文件(包括包含该功能的文件)链接到最终应用程序。 This error comes from the linking phase, not from the compiling phase. 此错误来自链接阶段,而不是来自编译阶段。

Furthermore, I see from your error message that you're using a C++ compiler for C code. 此外,我从您的错误消息中看到您正在为C代码使用C ++编译器。 You don't need to do that: it would be more optimal to use a C compiler. 您不需要这样做:使用C编译器会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM