Skip to content

Building and Testing

Jordan Bayles edited this page May 5, 2026 · 2 revisions

Meson and Ninja

Thanks to David Seifert (@SoapGentoo), the maintainers now use Meson and Ninja to build for debugging, as well as for continuous integration (see meson.yml). Other systems may work, but minor things like version strings might break.

First, install both Meson and Ninja (both require Python 3):

# Install Meson
pip install meson

# Install Ninja
pip install ninja

Then, configure and build the project:

cd jsoncpp/

BUILD_TYPE=release # plain, debug, debugoptimized, release, minsize
LIB_TYPE=shared    # shared, static

meson setup --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} build-${LIB_TYPE} .
ninja -v -C build-${LIB_TYPE} test

CMake

Deprecated: Still functional, but the version string may be inaccurate.

CMake is a C++ Makefiles/Solution generator. It is usually available on most Linux systems as a package. On Ubuntu:

sudo apt-get install cmake

Note: Python is required to run the JSON reader/writer tests. If missing, the build will skip running those tests.

When running CMake, a few parameters are required:

  • Build Directory: Where the makefiles/solution are generated. Used to store objects, libraries, and executables.
  • Generator: Makefiles or Visual Studio solution? 32-bit or 64-bit?

Generating via cmake-gui

  1. Set "Where is the source code" to the source directory.
  2. Set "Where to build the binaries" to the build directory.
  3. Check the "Grouped" box.
  4. Review JsonCpp build options (check BUILD_SHARED_LIBS to build as a dynamic library).
  5. Click Configure, then Generate.
  6. The generated solution/makefiles can be found in the binary directory.

Generating via Command Line (Unix)

From the source directory:

mkdir -p build/debug
cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" ../..
make

For a proper pkg-config file, add:

-DCMAKE_INSTALL_INCLUDEDIR=include/jsoncpp
  • Run cmake -h to see the list of available generators (passed using the -G option).
  • By default, CMake hides compilation commands. To see them, add -DCMAKE_VERBOSE_MAKEFILE=true when generating makefiles.

When building the solution file on Visual Studio, it may try to run the tests. If you build a DLL of jsoncpp, it must be installed or copied into the output directory containing jsontestrunner_exe.exe.

Alternative CMake Usage

See Issue #455.

The jsoncppConfig.cmake file defines the INTERFACE_INCLUDE_DIRECTORIES property for the jsoncpp_lib and jsoncpp_lib_static targets. You need to query the target property and set it manually:

get_target_property(JSON_INC_PATH jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${JSON_INC_PATH})

Linking is done via:

target_link_libraries(${PROJECT_NAME} jsoncpp_lib)

Package Managers

Package manager ports (like Conan and vcpkg) are community-maintained. We do not provide official support or documentation for them. Please refer to their respective repositories and documentation for instructions, and report any issues directly to those communities.

Bazel

Instructions for using Bazel can be found in the Bazel Central Registry.

macOS

On macOS, the Meson and Ninja instructions above are the most straightforward way to build the libraries.

If you are compiling and running the examples manually, the following command line may be helpful:

g++ readFromString.cpp -ljsoncpp -std=c++11 -o readFromString -L../../build-shared -Wl,-rpath,../../build-shared

Including -Wl,-rpath,../../build-shared prevents runtime linking errors caused by missing LC_RPATH configurations.

Clone this wiki locally