The complete pugixml source consists of three files - one source file, <codeclass="filename">pugixml.cpp</code>,
and two header files, <codeclass="filename">pugixml.hpp</code> and <codeclass="filename">pugiconfig.hpp</code>. <codeclass="filename">pugixml.hpp</code> is the primary
header which you need to include in order to use pugixml classes/functions;
<codeclass="filename">pugiconfig.hpp</code> is a supplementary configuration file (see <aclass="xref"href="install.html#manual.install.building.config"title="Additional configuration options"> Additional configuration
options</a>).
The rest of this guide assumes that <codeclass="filename">pugixml.hpp</code> is either in the current directory
or in one of include directories of your projects, so that <codeclass="computeroutput"><spanclass="preprocessor">#include</span><spanclass="string">"pugixml.hpp"</span></code>
can find the header; however you can also use relative path (i.e. <codeclass="computeroutput"><spanclass="preprocessor">#include</span><spanclass="string">"../libs/pugixml/src/pugixml.hpp"</span></code>)
or include directory-relative path (i.e. <codeclass="computeroutput"><spanclass="preprocessor">#include</span>
<aname="manual.install.building.embed"></a><aclass="link"href="install.html#manual.install.building.embed"title="Building pugixml as a part of another static library/executable"> Building pugixml as
The easiest way to build pugixml is to compile the source file, <codeclass="filename">pugixml.cpp</code>,
along with the existing library/executable. This process depends on the
method of building your application; for example, if you're using Microsoft
Visual Studio<sup>[<aname="trademarks"href="#ftn.trademarks"class="footnote">1</a>]</sup>, Apple Xcode, Code::Blocks or any other IDE, just add <codeclass="filename">pugixml.cpp</code> to
<preclass="programlisting">pugixml.cpp(3477) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?</pre>
<aname="manual.install.building.static"></a><aclass="link"href="install.html#manual.install.building.static"title="Building pugixml as a standalone static library"> Building pugixml as
a standalone static library</a>
</h4></div></div></div>
<p>
It's possible to compile pugixml as a standalone static library. This process
depends on the method of building your application; pugixml distribution
comes with project files for several popular IDEs/build systems. There
are project files for Apple XCode3, Code::Blocks, Codelite, Microsoft Visual
Studio 2005, 2008, 2010, and configuration scripts for CMake and premake4.
You're welcome to submit project files/build scripts for other software;
see <aclass="xref"href="../manual.html#manual.overview.feedback"title="Feedback"> Feedback</a>.
</p>
<p>
There are two projects for each version of Microsoft Visual Studio: one
for dynamically linked CRT, which has a name like <codeclass="filename">pugixml_vs2008.vcproj</code>,
and another one for statically linked CRT, which has a name like <codeclass="filename">pugixml_vs2008_static.vcproj</code>.
You should select the version that matches the CRT used in your application;
the default option for new projects created by Microsoft Visual Studio
is dynamically linked CRT, so unless you changed the defaults, you should
use the version with dynamic CRT (i.e. <codeclass="filename">pugixml_vs2008.vcproj</code> for Microsoft
Visual Studio 2008).
</p>
<p>
In addition to adding pugixml project to your workspace, you'll have to
make sure that your application links with pugixml library. If you're using
Microsoft Visual Studio 2005/2008, you can add a dependency from your application
project to pugixml one. If you're using Microsoft Visual Studio 2010, you'll
have to add a reference to your application project instead. For other
<aname="manual.install.building.shared"></a><aclass="link"href="install.html#manual.install.building.shared"title="Building pugixml as a standalone shared library"> Building pugixml as
a standalone shared library</a>
</h4></div></div></div>
<p>
It's possible to compile pugixml as a standalone shared library. The process
is usually similar to the static library approach; however, no preconfigured
projects/scripts are included into pugixml distribution, so you'll have
to do it yourself. Generally, if you're using GCC-based toolchain, the
process does not differ from building any other library as DLL (adding
-shared to compilation flags should suffice); if you're using MSVC-based
toolchain, you'll have to explicitly mark exported symbols with a declspec
<aname="manual.install.building.header"></a><aclass="link"href="install.html#manual.install.building.header"title="Using pugixml in header-only mode"> Using pugixml in header-only
mode</a>
</h4></div></div></div>
<p>
It's possible to use pugixml in header-only mode. This means that all source
code for pugixml will be included in every translation unit that includes
<codeclass="filename">pugixml.hpp</code>. This is how most of Boost and STL libraries work.
</p>
<p>
Note that there are advantages and drawbacks of this approach. Header mode
may improve tree traversal/modification performance (because many simple
functions will be inlined), if your compiler toolchain does not support
link-time optimization, or if you have it turned off (with link-time optimization
the performance should be similar to non-header mode). However, since compiler
now has to compile pugixml source once for each translation unit that includes
it, compilation times may increase noticeably. If you want to use pugixml
in header mode but do not need XPath support, you can consider disabling
it by using <aclass="link"href="install.html#PUGIXML_NO_XPATH">PUGIXML_NO_XPATH</a> define
Note that it is safe to compile <codeclass="filename">pugixml.cpp</code> if <codeclass="computeroutput"><spanclass="identifier">PUGIXML_HEADER_ONLY</span></code>
is defined - so if you want to i.e. use header-only mode only in Release
configuration, you can include pugixml.cpp in your project (see <aclass="xref"href="install.html#manual.install.building.embed"title="Building pugixml as a part of another static library/executable"> Building pugixml as
a part of another static library/executable</a>),
and conditionally enable header-only mode in <codeclass="filename">pugiconfig.hpp</code>, i.e.:
command-line. Consistency is important: the definitions should match in
all source files that include <codeclass="filename">pugixml.hpp</code> (including pugixml sources) throughout
the application. Adding defines to <codeclass="filename">pugiconfig.hpp</code> lets you guarantee this,
unless your macro definition is wrapped in preprocessor <codeclass="computeroutput"><spanclass="preprocessor">#if</span></code>/<codeclass="computeroutput"><spanclass="preprocessor">#ifdef</span></code> directive and this directive
is not consistent. <codeclass="filename">pugiconfig.hpp</code> will never contain anything but comments,
which means that when upgrading to a new version, you can safely leave
is used instead. For example, to specify fixed calling convention, you
can define <codeclass="computeroutput"><spanclass="identifier">PUGIXML_FUNCTION</span></code>
to i.e. <codeclass="computeroutput"><spanclass="identifier">__fastcall</span></code>. Another
example is DLL import/export attributes in MSVC (see <aclass="xref"href="install.html#manual.install.building.shared"title="Building pugixml as a standalone shared library"> Building pugixml as
and <aname="PUGIXML_MEMORY_XPATH_PAGE_SIZE"></a><codeclass="literal">PUGIXML_MEMORY_XPATH_PAGE_SIZE</code>
can be used to customize certain important sizes to optimize memory usage
for the application-specific patterns. For details see <aclass="xref"href="dom.html#manual.dom.memory.tuning"title="Memory consumption tuning"> Memory consumption tuning</a>.
<divclass="footnote"><p><sup>[<aname="ftn.trademarks"href="#trademarks"class="para">1</a>] </sup>All trademarks used are properties of their respective