You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. `json-c` {#mainpage}
  2. ========
  3. JSON-C - A JSON implementation in C
  4. -----------------------------------
  5. Build Status
  6. * [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&svg=true)](https://ci.appveyor.com/project/hawicz/json-c)
  7. * [![Travis Build Status](https://travis-ci.org/json-c/json-c.svg?branch=master)](https://travis-ci.org/json-c/json-c)
  8. JSON-C implements a reference counting object model that allows you to easily
  9. construct JSON objects in C, output them as JSON formatted strings and parse
  10. JSON formatted strings back into the C representation of JSON objects.
  11. It aims to conform to [RFC 7159](https://tools.ietf.org/html/rfc7159).
  12. Building on Unix with `git`, `gcc` and `autotools`
  13. --------------------------------------------------
  14. Home page for json-c: https://github.com/json-c/json-c/wiki
  15. ### Prerequisites:
  16. See also the "Installing prerequisites" section below.
  17. - `gcc`, `clang`, or another C compiler
  18. - `libtool>=2.2.6b`
  19. If you're not using a release tarball, you'll also need:
  20. - `autoconf>=2.64` (`autoreconf`)
  21. - `automake>=1.10.3`
  22. Make sure you have a complete `libtool` install, including `libtoolize`.
  23. ### Build instructions:
  24. `json-c` GitHub repo: https://github.com/json-c/json-c
  25. ```sh
  26. $ git clone https://github.com/json-c/json-c.git
  27. $ cd json-c
  28. $ sh autogen.sh
  29. ```
  30. followed by
  31. ```sh
  32. $ ./configure # --enable-threading
  33. $ make
  34. $ make install
  35. ```
  36. To build and run the test programs:
  37. ```sh
  38. $ make check
  39. ```
  40. Building with partial threading support
  41. ----------------------------------------
  42. Although json-c does not support fully multi-threaded access to
  43. object trees, it has some code to help make use in threaded programs
  44. a bit safer. Currently, this is limited to using atomic operations for
  45. json_object_get() and json_object_put().
  46. Since this may have a performance impact, of at least 3x slower
  47. according to https://stackoverflow.com/a/11609063, it is disabled by
  48. default. You may turn it on by adjusting your configure command with:
  49. --enable-threading
  50. Separately, the default hash function used for object field keys,
  51. lh_char_hash, uses a compare-and-swap operation to ensure the randomly
  52. seed is only generated once. Because this is a one-time operation, it
  53. is always compiled in when the compare-and-swap operation is available.
  54. Linking to `libjson-c`
  55. ----------------------
  56. If your system has `pkgconfig`,
  57. then you can just add this to your `makefile`:
  58. ```make
  59. CFLAGS += $(shell pkg-config --cflags json-c)
  60. LDFLAGS += $(shell pkg-config --libs json-c)
  61. ```
  62. Without `pkgconfig`, you would do something like this:
  63. ```make
  64. JSON_C_DIR=/path/to/json_c/install
  65. CFLAGS += -I$(JSON_C_DIR)/include/json-c
  66. LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
  67. ```
  68. Install prerequisites
  69. -----------------------
  70. If you are on a relatively modern system, you'll likely be able to install
  71. the prerequisites using your OS's packaging system.
  72. ### Install using apt (e.g. Ubuntu 16.04.2 LTS)
  73. ```sh
  74. sudo apt install git
  75. sudo apt install autoconf automake libtool
  76. sudo apt install valgrind # optional
  77. ```
  78. Then start from the "git clone" command, above.
  79. ### Manually install and build autoconf, automake and libtool
  80. For older OS's that don't have up-to-date version of the packages will
  81. require a bit more work. For example, CentOS release 5.11, etc...
  82. ```sh
  83. curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
  84. curl -O http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
  85. curl -O http://ftp.gnu.org/gnu/libtool/libtool-2.2.6b.tar.gz
  86. tar xzf autoconf-2.69.tar.gz
  87. tar xzf automake-1.15.tar.gz
  88. tar xzf libtool-2.2.6b.tar.gz
  89. export PATH=${HOME}/ac_install/bin:$PATH
  90. (cd autoconf-2.69 && \
  91. ./configure --prefix ${HOME}/ac_install && \
  92. make && \
  93. make install)
  94. (cd automake-1.15 && \
  95. ./configure --prefix ${HOME}/ac_install && \
  96. make && \
  97. make install)
  98. (cd libtool-2.2.6b && \
  99. ./configure --prefix ${HOME}/ac_install && \
  100. make && \
  101. make install)
  102. ```