mirror of
https://github.com/nlohmann/json.git
synced 2026-10-29 09:05:42 +00:00
deploy: a47170346a
This commit is contained in:
1 parent
b36f8a9821
commit
11a863958e
1180 files changed
+14211
-6025
No files matched your search
+14
-11
@@ -1,14 +1,17 @@
|
||||
<!doctype html><html lang=en class=no-js> <head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=author content="Niels Lohmann"><link href="https://json.nlohmann.me/integration/" rel="canonical"><link href=../features/json_view/ rel=prev><link href=migration_guide/ rel=next><link rel=icon href=../assets/images/favicon.png><meta name=generator content="mkdocs-1.6.1, mkdocs-material-9.7.7"><title>Integration - JSON for Modern C++</title><link rel=stylesheet href=../assets/stylesheets/main.ec1eaa64.min.css><link rel=stylesheet href=../assets/stylesheets/palette.ab4e12ef.min.css><link rel="stylesheet" href="../assets/external/fonts.googleapis.com/css.61a430c9.css"><style>:root{--md-text-font:"Roboto";--md-code-font:"JetBrains Mono"}</style><link rel=stylesheet href=../css/custom.css><script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script></head> <body dir=ltr data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=indigo> <input class=md-toggle data-md-toggle=drawer type=checkbox id=__drawer autocomplete=off> <input class=md-toggle data-md-toggle=search type=checkbox id=__search autocomplete=off> <label class=md-overlay for=__drawer></label> <div data-md-component=skip> <a href=#integration class=md-skip> Skip to content </a> </div> <div data-md-component=announce> </div> <header class=md-header data-md-component=header> <nav class="md-header__inner md-grid" aria-label=Header> <a href=.. title="JSON for Modern C++" class="md-header__button md-logo" aria-label="JSON for Modern C++" data-md-component=logo> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg> </a> <label class="md-header__button md-icon" for=__drawer> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg> </label> <div class=md-header__title data-md-component=header-title> <div class=md-header__ellipsis> <div class=md-header__topic> <span class=md-ellipsis> JSON for Modern C++ </span> </div> <div class=md-header__topic data-md-component=header-topic> <span class=md-ellipsis> Integration </span> </div> </div> </div> <form class=md-header__option data-md-component=palette> <input class=md-option data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=indigo aria-label="Switch to dark mode" type=radio name=__palette id=__palette_0> <label class="md-header__button md-icon" title="Switch to dark mode" for=__palette_1 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> <input class=md-option data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme=slate data-md-color-primary=indigo data-md-color-accent=indigo aria-label="Switch to light mode" type=radio name=__palette id=__palette_1> <label class="md-header__button md-icon" title="Switch to light mode" for=__palette_0 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12s-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> </form> <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script> <label class="md-header__button md-icon" for=__search> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg> </label> <div class=md-search data-md-componentLine truncated
|
||||
A[Add the library to a C++ project] --> B{Already using CMake?}
|
||||
B -- no --> C{Using pkg-config or plain Makefiles?}
|
||||
C -- yes --> D[pkg-config]
|
||||
C -- no --> E[Copy the single header]
|
||||
B -- yes --> F{Library installed system-wide?}
|
||||
F -- yes --> G["find_package()"]
|
||||
F -- no --> H{Use a package manager?}
|
||||
H -- yes --> I[Package manager]
|
||||
H -- no --> J["add_subdirectory() or FetchContent"]</code></pre> <ul> <li><strong>Copy the single header</strong>, as described <a href=#header-only>below</a> — no build-system integration required.</li> <li><strong>CMake</strong>: use <a href=cmake/#external><code>find_package()</code></a> if the library is already installed, <a href=cmake/#embedded><code>add_subdirectory()</code></a> to embed the source tree, or <a href=cmake/#fetchcontent><code>FetchContent</code></a> to download it at configure time; see <a href=cmake/ >CMake</a>.</li> <li><strong>Package managers</strong>: install the library with a package manager such as Homebrew, Conan, or vcpkg; see <a href=package_managers/ >Package Managers</a>.</li> <li><strong>pkg-config</strong>: if you use bare Makefiles instead of CMake, <a href=pkg-config/ >pkg-config</a> can supply the include flags for an already-installed library.</li> </ul> <p>Once the library is integrated, see the <a href=migration_guide/ >Migration Guide</a> for how to keep your code future-proof across releases.</p> <h2 id=header-only>Header only<a class=headerlink href=#header-only title="Permanent link">¶</a></h2> <p><a href="https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp"><code>json.hpp</code></a> is the single required file in <code>single_include/nlohmann</code> or <a href="https://github.com/nlohmann/json/releases">released here</a>. You need to add</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf><nlohmann/json.hpp></span>
|
||||
<!doctype html><html lang=en class=no-js> <head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="JSON for Modern C++ is a header-only C++11 library that makes JSON a first-class data type."><meta name=author content="Niels Lohmann"><link href="https://json.nlohmann.me/integration/" rel="canonical"><link href=../features/json_view/ rel=prev><link href=migration_guide/ rel=next><link rel=icon href=../assets/images/favicon.png><meta name=generator content="mkdocs-1.6.1, mkdocs-material-9.7.7"><title>Integration - JSON for Modern C++</title><link rel=stylesheet href=../assets/stylesheets/main.ec1eaa64.min.css><link rel=stylesheet href=../assets/stylesheets/palette.ab4e12ef.min.css><link rel=stylesheet href=../css/custom.css><link rel=stylesheet href=../css/brand.css><link rel=stylesheet href=../css/fig-sax.css><link rel=stylesheet href=../css/fig-jsonview.css><link rel=stylesheet href=../css/fig-exceptions.css><link rel=stylesheet href=../css/fig-pointer.css><link rel=stylesheet href=../css/fig-charts.css><link rel=stylesheet href=../css/fig-integration.css><link rel=stylesheet href=../css/fig-macros.css><script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script></head> <body dir=ltr data-md-color-scheme=default data-md-color-primary=custom data-md-color-accent=custom> <input class=md-toggle data-md-toggle=drawer type=checkbox id=__drawer autocomplete=off> <input class=md-toggle data-md-toggle=search type=checkbox id=__search autocomplete=off> <label class=md-overlay for=__drawer></label> <div data-md-component=skip> <a href=#integration class=md-skip> Skip to content </a> </div> <div data-md-component=announce> </div> <header class=md-header data-md-component=header> <nav class="md-header__inner md-grid" aria-label=Header> <a href=.. title="JSON for Modern C++" class="md-header__button md-logo" aria-label="JSON for Modern C++" data-md-component=logo> <img src=../images/wordmark-header.svg alt=logo> </a> <label class="md-header__button md-icon" for=__drawer> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg> </label> <div class=md-header__title data-md-component=header-title> <div class=md-header__ellipsis> <div class=md-header__topic> <span class=md-ellipsis> JSON for Modern C++ </span> </div> <div class=md-header__topic data-md-component=header-topic> <span class=md-ellipsis> Integration </span> </div> </div> </div> <form class=md-header__option data-md-component=palette> <input class=md-option data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme=default data-md-color-primary=custom data-md-color-accent=custom aria-label="Switch to dark mode" type=radio name=__palette id=__palette_0> <label class="md-header__button md-icon" title="Switch to dark mode" for=__palette_1 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> <input class=md-option data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme=slate data-md-color-primary=custom data-md-color-accent=custom aria-label="Switch to light mode" type=radio name=__palette id=__palette_1> <label class="md-header__button md-icon" title="Switch to light mode" for=__palette_0 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12s-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> </form> <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script> <label class="md-header__button md-icon" for=__search> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.Line truncated
|
||||
A[Add the library to a C++ project] --> B{{Using CMake?}}
|
||||
B -- no --> C{{Package manager available?}}
|
||||
C -- yes --> D["<b>Use a package manager</b><br>see Package Managers"]
|
||||
C -- no --> E["<b>Copy the single header</b><br>see Header only"]
|
||||
B -- yes --> F{{Already installed?}}
|
||||
F -- yes --> G["<b>find_package</b><br>see CMake, External"]
|
||||
F -- no --> H{{CMake 3.14 or later?}}
|
||||
H -- yes --> I["<b>FetchContent</b><br>see CMake, FetchContent"]
|
||||
H -- no --> J["<b>add_subdirectory</b><br>see CMake, Embedded"]
|
||||
G --> T["<code>nlohmann_json::nlohmann_json</code>"]
|
||||
I --> T
|
||||
J --> T</code></pre> <p class=nj-caption>Choosing an integration method: answer the questions in the hexagons from top to bottom to reach a method. All CMake methods end at the same target, <code>nlohmann_json::nlohmann_json</code>; the list below links to each method.</p> <ul> <li><strong>Single header</strong>: copy <a href=#header-only><code>json.hpp</code></a> into your project; no build-system integration required.</li> <li><strong>CMake</strong>, see <a href=cmake/ >CMake</a>:<ul> <li><a href=cmake/#external><code>find_package()</code></a> if the library is already installed;</li> <li><a href=cmake/#fetchcontent><code>FetchContent</code></a> to download it at configure time (CMake 3.14 or later);</li> <li><a href=cmake/#embedded><code>add_subdirectory()</code></a> to embed a vendored copy of the source tree;</li> <li>or <a href=cmake/#supporting-both>support both</a> with an option that selects installed or vendored.</li> </ul> </li> <li><strong>Package managers</strong>: install the library with Homebrew, Conan, vcpkg, or one of the many others; see <a href=package_managers/ >Package Managers</a> for the full list.</li> <li><strong>pkg-config</strong>: if you use bare Makefiles instead of CMake, <a href=pkg-config/ >pkg-config</a> supplies the include flags for an already-installed library.</li> </ul> <p>Once the library is integrated, see the <a href=migration_guide/ >Migration Guide</a> for how to keep your code future-proof across releases.</p> <h2 id=header-only>Header only<a class=headerlink href=#header-only title="Permanent link">¶</a></h2> <p><a href="https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp"><code>json.hpp</code></a> is the single required file in <code>single_include/nlohmann</code> or <a href="https://github.com/nlohmann/json/releases">released here</a>. You need to add</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf><nlohmann/json.hpp></span>
|
||||
|
||||
<span class=c1>// for convenience</span>
|
||||
<span class=k>using</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
|
||||
</code></pre></div> <p>to the files you want to process <abbr title="JavaScript Object Notation">JSON</abbr> and set the necessary switches to enable C++11 (e.g., <code>-std=c++11</code> for <abbr title="GNU Compiler Collection">GCC</abbr> and Clang).</p> <div class="admonition tip"> <p class=admonition-title>Which file do I download?</p> <p>For a project without a package manager, the library itself, including the <code>_json</code> literals, is <strong>one file</strong>: <a href="https://github.com/nlohmann/json/releases/latest/download/json.hpp"><code>json.hpp</code></a> from the <a href="https://github.com/nlohmann/json/releases">releases page</a>. You do not need to clone the repository, build anything, or link a library. Put the file in a directory named <code>nlohmann</code> that is on your include path (for example <code>third_party/nlohmann/json.hpp</code> with <code>-I third_party</code>), so that <code>#include <nlohmann/json.hpp></code> works. Download the companion headers listed below only if you use them: <code>json_view.hpp</code> for the <a href=../features/json_view/ >zero-copy views</a>, <code>json_fwd.hpp</code> for forward declarations, and <code>json_literals.hpp</code> if you define <code>JSON_NO_AUTOMATIC_UDLS</code>. Keep them in the same <code>nlohmann</code> directory.</p> <p>Do not copy only parts of the repository's <code>include/</code> directory: the headers in it include each other and must be kept together. If your <abbr title="Integrated Development Environment">IDE</abbr> reports "cannot open source file" while the compiler succeeds, the compiler's include path is set correctly but the <abbr title="Integrated Development Environment">IDE</abbr>'s is not; add the same directory to the <abbr title="Integrated Development Environment">IDE</abbr>'s include paths.</p> </div> <p>You can further use file <a href="https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_fwd.hpp"><code>single_include/nlohmann/json_fwd.hpp</code></a> for forward declarations (see <a href=compile_times/ >Compile times</a>), and file <a href="https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_literals.hpp"><code>single_include/nlohmann/json_literals.hpp</code></a> for the user-defined string literals if you define <a href=../api/macros/json_no_automatic_udls/ ><code>JSON_NO_AUTOMATIC_UDLS</code></a>.</p> <p>For the read-only, non-owning <a href=../api/basic_json_document/ ><code>basic_json_document</code></a>/<a href=../api/basic_json_view/ ><code>basic_json_view</code></a> types, additionally include <a href="https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_view.hpp"><code>single_include/nlohmann/json_view.hpp</code></a>; see <a href=../features/json_view/ >Zero-copy <abbr title="JavaScript Object Notation">JSON</abbr> views</a>.</p> <h2 id=notes-for-builds-and-distribution>Notes for builds and distribution<a class=headerlink href=#notes-for-builds-and-distribution title="Permanent link">¶</a></h2> <p><strong>Reproducible and path-independent builds.</strong> The runtime assertions use <code>assert</code>, which embeds the name of the source file (<code>__FILE__</code>) in the binary. Release builds do not contain them, because they define <code>NDEBUG</code>. If you compile with assertions enabled and need binaries that do not depend on the build directory, either define <code>NDEBUG</code> or map the prefix of the path with the compiler option <code>-ffile-prefix-map=<old>=<new></code> (<abbr title="GNU Compiler Collection">GCC</abbr> 8 and later, Clang 10 and later). See <a href=../features/assertions/ >Runtime assertions</a>.</p> <p><strong>There is no separate source file to compile.</strong> The library is header-only, so there is no <code>.cpp</code> that could be built with different options than the code that includes it. It is also not available as a precompiled library. To compile the library with optimizations in an otherwise unoptimized build (for example to parse large files in a debug build, which is slow because of the unoptimized code and the checks of the debug standard library), keep the code that uses <code>json</code> in a separate source file and set the options for that file only. <a href=compile_times/ >Compile times</a> shows how to <a href=compile_times/#instantiate-basic_json-once>instantiate <code>basic_json</code> once</a>.</p> <p><strong>Debugger visualization.</strong> The Natvis file works with the Visual Studio debugger, including the <code>cppvsdbg</code> engine in Visual Studio Code, but not with debuggers that wrap <abbr title="LLVM Debugger">LLDB</abbr>, such as <code>codelldb</code>; see <a href=../home/debugging/ >Debugging</a>.</p> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">¶</a></h2> <ul> <li><a href=cmake/ >CMake</a> - integrate the library into a CMake project</li> <li><a href=package_managers/ >Package managers</a></li> <liLine truncated
|
||||
</code></pre></div> <p>to the files you want to process <abbr title="JavaScript Object Notation">JSON</abbr> and set the necessary switches to enable C++11 (e.g., <code>-std=c++11</code> for <abbr title="GNU Compiler Collection">GCC</abbr> and Clang).</p> <div class="admonition tip"> <p class=admonition-title>Which file do I download?</p> <p>For a project without a package manager, the library itself, including the <code>_json</code> literals, is <strong>one file</strong>: <a href="https://github.com/nlohmann/json/releases/latest/download/json.hpp"><code>json.hpp</code></a> from the <a href="https://github.com/nlohmann/json/releases">releases page</a>. You do not need to clone the repository, build anything, or link a library. Put the file in a directory named <code>nlohmann</code> that is on your include path (for example <code>third_party/nlohmann/json.hpp</code> with <code>-I third_party</code>), so that <code>#include <nlohmann/json.hpp></code> works. Download the companion headers listed below only if you use them: <code>json_view.hpp</code> for the <a href=../features/json_view/ >zero-copy views</a>, <code>json_fwd.hpp</code> for forward declarations, and <code>json_literals.hpp</code> if you define <code>JSON_NO_AUTOMATIC_UDLS</code>. Keep them in the same <code>nlohmann</code> directory.</p> <p>Do not copy only parts of the repository's <code>include/</code> directory: the headers in it include each other and must be kept together. If your <abbr title="Integrated Development Environment">IDE</abbr> reports "cannot open source file" while the compiler succeeds, the compiler's include path is set correctly but the <abbr title="Integrated Development Environment">IDE</abbr>'s is not; add the same directory to the <abbr title="Integrated Development Environment">IDE</abbr>'s include paths.</p> </div> <p>You can further use file <a href="https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_fwd.hpp"><code>single_include/nlohmann/json_fwd.hpp</code></a> for forward declarations (see <a href=compile_times/ >Compile times</a>), and file <a href="https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_literals.hpp"><code>single_include/nlohmann/json_literals.hpp</code></a> for the user-defined string literals if you define <a href=../api/macros/json_no_automatic_udls/ ><code>JSON_NO_AUTOMATIC_UDLS</code></a>.</p> <p>For the read-only, non-owning <a href=../api/basic_json_document/ ><code>basic_json_document</code></a>/<a href=../api/basic_json_view/ ><code>basic_json_view</code></a> types, additionally include <a href="https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_view.hpp"><code>single_include/nlohmann/json_view.hpp</code></a>; see <a href=../features/json_view/ >Zero-copy <abbr title="JavaScript Object Notation">JSON</abbr> views</a>.</p> <h2 id=notes-for-builds-and-distribution>Notes for builds and distribution<a class=headerlink href=#notes-for-builds-and-distribution title="Permanent link">¶</a></h2> <p><strong>Reproducible and path-independent builds.</strong> The runtime assertions use <code>assert</code>, which embeds the name of the source file (<code>__FILE__</code>) in the binary. Release builds do not contain them, because they define <code>NDEBUG</code>. If you compile with assertions enabled and need binaries that do not depend on the build directory, either define <code>NDEBUG</code> or map the prefix of the path with the compiler option <code>-ffile-prefix-map=<old>=<new></code> (<abbr title="GNU Compiler Collection">GCC</abbr> 8 and later, Clang 10 and later). See <a href=../features/assertions/ >Runtime assertions</a>.</p> <p><strong>There is no separate source file to compile.</strong> The library is header-only, so there is no <code>.cpp</code> that could be built with different options than the code that includes it. It is also not available as a precompiled library. To compile the library with optimizations in an otherwise unoptimized build (for example to parse large files in a debug build, which is slow because of the unoptimized code and the checks of the debug standard library), keep the code that uses <code>json</code> in a separate source file and set the options for that file only. <a href=compile_times/ >Compile times</a> shows how to <a href=compile_times/#instantiate-basic_json-once>instantiate <code>basic_json</code> once</a>.</p> <p><strong>Debugger visualization.</strong> The Natvis file works with the Visual Studio debugger, including the <code>cppvsdbg</code> engine in Visual Studio Code, but not with debuggers that wrap <abbr title="LLVM Debugger">LLDB</abbr>, such as <code>codelldb</code>; see <a href=../home/debugging/ >Debugging</a>.</p> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">¶</a></h2> <ul> <li><a href=cmake/ >CMake</a> - integrate the library into a CMake project</li> <li><a href=package_managers/ >Package managers</a> - instalLine truncated
|
||||
Reference in new issue
Block a user