简体   繁体   中英

Undefined reference gcc

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 to json_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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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