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?

0

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

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..
I understand. See my further explanation.
That's it! Thanks! (Can and will accept your answer in four minutes)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.