Thomas K
Thomas K

Reputation: 6196

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

Upvotes: 5

Views: 14833

Answers (1)

user529758
user529758

Reputation:

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

Upvotes: 8

Related Questions