0

I'm trying to write a simple ANSI C script that uses cURL to do some REST calls and then uses Jsmn to parse the JSON response bodies. I've got all the cURL parts working, but I can't figure out how to get things linked up properly with jsmn. So to start, I've been trying to build their examples.

For instance, after cloning the repo, there is an examples/ directory with a file in it called simple.c. I tried to build that with this command:

$ gcc -o simple simple.c

But that resulted in an error response that looked something like this:

/tmp/ccGbLj94.o: In function `main':
simple.c:(.text+0xc8): undefined reference to `jsmn_init'
simple.c:(.text+0x10c): undefined reference to `jsmn_parse'
collect2: error: ld returned 1 exit status

I confess I'm rather new to doing anything in ANSI C, and all things Linux in general. I believe that I have to tell gcc to link in the source but am unsure how to do that correctly.

Just so you know what I've tried so far, after running make as the readme file instructs, I copied the resultant jsmn.o and libjsmn.a files to /usr/local/lib, and chmod'ed 0755 on the jsmn.o file. Then I tried again by issuing this command:

$ gcc -ljsmn -o simple simple.c

But unfortunately it still had the exact same error output.

alk
  • 66,653
  • 10
  • 83
  • 219
soapergem
  • 7,597
  • 16
  • 79
  • 124

1 Answers1

0

add -ljsmn to your command line - make sure your ld_library_path points to the directory that contains your library (man gcc, man ld are your friends)

KevinDTimm
  • 13,876
  • 3
  • 39
  • 59