1

I have a libnfc project that I compile with make-install and run my file with ./xxx Now I want to use json-c in xxx.c but a simple "#include <json/json.h>" does not work. How can I access the json-c methods from xxx.c?

Thanks for your answers,

Sophie

0decimal0
  • 3,884
  • 2
  • 24
  • 39
user1416721
  • 21
  • 2
  • 4
  • What error do you get? If it is "undefined reference to..." you need to link to the library as well as including its header. If you post sample code plus build command and the error you get, someone will probably explain the exact changes you need – simonc Jun 30 '13 at 16:21
  • Please show us the relevant parts of your code, or at least the exact error message you're getting – djf Jun 30 '13 at 16:25
  • Edit: my codes looks as followed: xxx.c: ... #include ... char * string = ("{\"test\" : \"test test\"}"); json_object * jobj = json_tokener_parse(string); ... the following error shows up when doing make install: Undefined symbols for architecture x86_64: "_json_tokener_parse", referenced from: _nfcforum_tag4_io in nfc-emulate-forum-tag4.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status json.h exists in the subdir. what do you mean with "link to the library"? Thanks for your fast answers so far, Sophie – user1416721 Jun 30 '13 at 16:46

2 Answers2

3

On linux you need add something like

-I/usr/include/json-c -L/usr/lib -ljson-c

to your compile command.

linux_art
  • 51
  • 3
-1

If u installed json-c as

/usr/local/include/json

Then use

gcc -ljson

If u installed as below path

/usr/local/include/json-c

then use gcc -ljson-c

ketan
  • 19,129
  • 42
  • 60
  • 98