Building and testing with Meson/Ninja
I want to compile jsoncpp with -fPIC through cmake. In the website for jsoncpp, it is explaining the way normally to compile like below. Mkdir -p build/debug cd build/debug cmake -DCMAKEBUILDTYPE=debug -DJSONCPPLIBBUILDSTATIC=ON -DJSONCPPLIBBUILDSHARED=OFF -G 'Unix Makefiles'./. Make How can i compile with -fPIC flag in. There are a variety of toolchains you can install on Windows for compiling C and C applications. Microsoft provides Visual Studio Community for free, and is a great IDE and toolchain. If you are developing exclusively for Windows, that is the tool I would recommend. For those who need or prefer the cross-platform GNU toolchain, you can install it using MSYS2. We will cover how to install gcc.
Thanks to David Seifert (@SoapGentoo), we (the maintainers) now use meson and ninja to build for debugging, as well as for continuous integration (see meson_builder.sh
). Other systems may work, but minor things like version strings might break.
C++ Json Parser
First, install both meson (which requires Python3) and ninja.
Then,
Building and testing with CMake
(Deprecated, but still works for now. The version string may soon be wrong.)
CMake is a C++ Makefiles/Solution generator. It is usually available on most Linux system as package. On Ubuntu:
Note that Python is also required to run the JSON reader/writer tests. Ifmissing, the build will skip running those tests.
When running CMake, a few parameters are required:
- A build directory where the makefiles/solution are generated. It is also usedto store objects, libraries and executables files.
- The generator to use: makefiles or Visual Studio solution? What version orVisual Studio, 32 or 64 bits solution?
Steps for generating solution/makefiles using cmake-gui
:
- Make 'source code' point to the source directory.
- Make 'where to build the binary' point to the directory to use for the build.
- Click on the 'Grouped' check box.
- Review JsonCpp build options (tick
BUILD_SHARED_LIBS
to build as adynamic library). - Click the configure button at the bottom, then the generate button.
- The generated solution/makefiles can be found in the binary directory.
Alternatively, from the command-line on Unix in the source directory:
For a good pkg-config file, add:
Running cmake -h
will display the list of available generators (passed usingthe -G
option).
By default CMake hides compilation commands. This can be modified by specifying-DCMAKE_VERBOSE_MAKEFILE=true
when generating makefiles.
When building the solution file on Visual Studio, it would try to run the tests. In this case, or when running the tests from the command line, if you build a DLL of jsoncpp, then it must be installed, or at least copied into the output directory holding jsontestrunner_exe.exe
Another approach for Cmake
The jsoncppConfig.cmake
defines property INTERFACE_INCLUDE_DIRECTORIES
for targets jsoncpp_lib
and jsoncpp_lib_static
.
You need to query the target property and set it manually:
Linking is done via:
Building and testing with Conan
When running CMake, a few parameters are required:
- A build directory where the makefiles/solution are generated. It is also usedto store objects, libraries and executables files.
- The generator to use: makefiles or Visual Studio solution? What version orVisual Studio, 32 or 64 bits solution?
Steps for generating solution/makefiles using cmake-gui
:
- Make 'source code' point to the source directory.
- Make 'where to build the binary' point to the directory to use for the build.
- Click on the 'Grouped' check box.
- Review JsonCpp build options (tick
BUILD_SHARED_LIBS
to build as adynamic library). - Click the configure button at the bottom, then the generate button.
- The generated solution/makefiles can be found in the binary directory.
Alternatively, from the command-line on Unix in the source directory:
For a good pkg-config file, add:
Running cmake -h
will display the list of available generators (passed usingthe -G
option).
By default CMake hides compilation commands. This can be modified by specifying-DCMAKE_VERBOSE_MAKEFILE=true
when generating makefiles.
When building the solution file on Visual Studio, it would try to run the tests. In this case, or when running the tests from the command line, if you build a DLL of jsoncpp, then it must be installed, or at least copied into the output directory holding jsontestrunner_exe.exe
Another approach for Cmake
The jsoncppConfig.cmake
defines property INTERFACE_INCLUDE_DIRECTORIES
for targets jsoncpp_lib
and jsoncpp_lib_static
.
You need to query the target property and set it manually:
Linking is done via:
Building and testing with Conan
(This works, but it currently uses cmake
, which is deprecated.)
Conan is an open source package manager intended for C/C++ projects.It is cross platform and build system agnostic.
Conan requires Python for running, and can be installed using pip:
Detailed instructions can be found on conan docs. Vogue artist makeup forever.
For build jsoncpp with conan, you need to create a conanfile.txt or a conanfile.py. The first is simpler, but the second is more flexible.
This is a sample conanfile.txt:
Note: cmake is not required, you can use other integrations. Or you can set the appropriate environment variables, using virtualenv generators.
Then run the following command from the conanfile directory:
This will try to download the appropriate package for your settings (OS, compiler, architecture) from the recipe packages. If it is not found, the package will be built.
Note: you do not need to install cmake to build jsoncpp using conan, because the recipe will download it automatically.
If you need, you can customize the jsoncpp recipe. Just clone/fork it from github.
See integrations instructions for how to use your build system with conan.
Building and testing with scons
No longer supported. But you might be able to recover it at commit at https://github.com/open-source-parsers/jsoncpp/commit/6d31cec7cf44dd7e14263f0ffbc888abf515d3dc .