C언어에서 json-c 라이브러리를 사용하여 json 파싱


GitHub repo로 가보자


README.md를 잘 읽어보면..


사전에 필요한 것들:

  • gcc, clang과 같은 C 컴파일러
  • libtool

tarball을 사용하지 않는다면, 이것들도 필요:

  • autoconf(autoreconf)
  • automake

나는 libtool, autoconf 및 automake를 설치했다.

우분투에서:

$ sudo apt-get install libtool $ sudo apt-get install autoconf

$ sudo apt-get install automake


clone하여 json-c 설치

$ git clone https://github.com/json-c/json-c.git $ cd json-c json-c$ sh autogen.sh json-c$ ./configure --prefix=/usr/local json-c$ make json-c$ make install

테스트 프로그램을 실행

$ make check


여기까지 했으면

json-c 라이브러리는 /usr/local/lib/에

json-c 헤더파일은 /usr/local/include/json-c/에 복사된다.


json-c 라이브러리를 사용하는 코드를 작성하고 Makefile을 통해 컴파일 하자.

작성한 코드는 json-example.c 라는 파일명으로 저장했다고 하면 Makefile은 아래와 같이 만들 수 있다.


Makefile 작성

all: static static:     gcc -static json-example.c -L/usr/local/lib -ljson-c -I/usr/local/include/json-c -o json-example-static     ./json-example-static shared:     gcc json-example.c -L/usr/local/lib -ljson-c -I/usr/local/include/json-c -o json-example-shared     ./json-example-shared .PHONY: all static shared


run

$ make static

또는

$ make shared


reference:

http://thesystemisntdown.coolaj86.com/2010/06/json-c-example.html


+ Recent posts