5

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?

Thomas K
  • 6,076
  • 5
  • 39
  • 56

1 Answers1

8

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
  • Sorry, I think I didn't make myself clear: I'm trying to compile main.c. The thing is, that the json.h file is not in a library. It's just an .h (and .c) file that I import and include.. – Thomas K Jun 27 '12 at 18:58
  • I understand. See my further explanation. –  Jun 27 '12 at 18:59
  • That's it! Thanks! (Can and will accept your answer in four minutes) – Thomas K Jun 27 '12 at 19:00