未定义参考GCC [英] Undefined reference gcc

查看:198
本文介绍了未定义参考GCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译使用GCC Ubuntu的我的计划,我得到这些错误:

When I try to compile my program on ubuntu using gcc, i get these errors:

main.c中:(文字+ 0x162):未定义引用 json_parse
  。main.c中:(文字+ 0x182):未定义引用
json_value_free

main.c:(.text+0x162): undefined reference to json_parse' main.c:(.text+0x182): undefined reference tojson_value_free'

但是,这些功能都包含在一个名为json.h文件,该文件导入我main.c中和我包括我的海湾合作​​委员会的命令。

However, these functions are included in a file called json.h, which I import in main.c and which I include in my gcc command.

任何人都得到了线索?

推荐答案

您不应该编制了json.h标题。未定义引用的的编译器错误,这是一个的链接错误的。这意味着你要么不包含json_value_free文件编译到code,或者没有链接到包含它的库。你应该做的,而不是试图编译头文件本身不是行动。

You should not compile the "json.h" header. The undefined reference is not a compiler error, it's a linker error. It means you have either not compiled the file containing json_value_free to your code, or haven't linked to the library containing it. You should do either action instead of trying to compile the header file itself.

所以,如果你有一个单独的json.c文件,您必须编译并连结到您的main.c文件。试试(我假设GCC):

So, if you have a separate json.c file, you have to compile and link it also to your main.c file. Try (I assume GCC):

gcc -o myprog main.c json.c

这篇关于未定义参考GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆