Undefined reference gcc

家住魔仙堡 提交于 2020-01-13 02:42:07

问题


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

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

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.

Anyone got a clue?


回答1:


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.

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


来源:https://stackoverflow.com/questions/11233078/undefined-reference-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!