rdf4cpp is a modern C++20 library providing basic RDF support.
The focus is correctness, performance and ease-of-use for basic building blocks like:
- parsing, validating and writing RDF data (N-Triples, Turtle, N-Quads, TriG)
- Complete and extensible literal datatypes (validation, functions, operations, subtype and promotion casting, mapping to C++ types, error handling, ...)
- Managing RDF nodes efficiently
- Blank node scoping (e.g., for RDF datasets)
rdf4cpp is not a SPARQL engine or reasoning engine, although it provides very basic support for triple/quad pattern matching on RDF graphs/datasets. rdf4cpp rather provides the necessary primitives to implement such engines.
We implement the following W3C standards:
- RDF 1.1 Concepts and Abstract Syntax
- XML XSD 1.1 Part 2: Datatypes (RDF related parts)
- OWL Real and Rational
- XPath and XQuery Functions and Operators 3.1 (SPARQL related parts)
#include <iostream> #include <rdf4cpp.hpp> int main() { using namespace ::rdf4cpp; using namespace ::rdf4cpp::shorthands; using namespace ::rdf4cpp::namespaces; using namespace ::rdf4cpp::datatypes; /// 1) basic dataset, graph and RDF node usage // using namespaces FOAF foaf{}; // common, predefined namespace Namespace const ex{"http://example.com/"}; // self-declared namespace Dataset dataset; // populate a named graph in the dataset auto &graph = dataset.graph(IRI{"http://ex.com/MyGraph"}); // IRI constructor graph.add({"http://example.com/Bob"_iri, "http://example.com/knows"_iri, "http://example.com/Alice"_iri}); // IRI shorthand graph.add({ex + "Alice", foaf + "knows", ex + "Bob"}); // using namespaces graph.add({ex + "Bob", foaf + "name", "Bob"_xsd_string}); // Literal datatype shorthand // serialize the dataset as N-Quads std::cout << "Dataset as N-Quads: \n" << dataset << std::endl; // 2) Using datatypes and arithmetics // typed Literal instantiation auto const d = Literal::make_typed_from_value<xsd::Double>(2.3); // factory function auto const ui = 42_xsd_uint; // Literal datatype shorthand auto const dec = "42.1"_xsd_decimal; // infinite precision decimals // basic arithmetics with automatic result type deduction auto const r1 = d * dec; // double * decimal → double auto const r2 = (ui + dec).round(); // round(integer + decimal) → decimal std::cout << "Using XSD datatypes, functions and operators: \n" << std::format("{} * {} = {}\n", d, dec, r1) << std::format("ceil({} + {}) = {}", ui, dec, r2) << std::endl; return 0; }rdf4cpp is consumed via Conan 2 but it is not available via Conan Center. Instead, it can be found on the artifactory of the DICE Research Group.
You need the package manager conan installed and set up. You can add the DICE artifactory with:
conan remote add dice-group https://conan.dice-research.org/artifactory/api/conan/tentrisTo use rdf4cpp, add it to your conanfile.txt:
[requires] rdf4cpp/0.1.11 For getting started how to use rdf4cpp, check out the examples directory and refer to our documentation.
rdf4cpp uses CMake and Conan 2. To build it, run:
wget https://github.com/conan-io/cmake-conan/raw/develop2/conan_provider.cmake -O conan_provider.cmake # download conan provider cmake -B build_dir -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake # configure and generate cmake --build build_dir # compileTo install it to your system, run afterward:
cd build_dir sudo make install-DBUILD_EXAMPLES=ON/OFF [default: OFF]: Build the examples.-DBUILD_TESTING=ON/OFF [default: OFF]: Build the tests.-DBUILD_SHARED_LIBS=ON/OFF [default: OFF]: Build a shared library instead of a static one.
- Linux distributions (x86-64, AArch64) (e.g. Ubuntu>=24.04, Fedora>=41, etc.) with:
- GCC>=14 (libstdc++>=14; used with both GCC and Clang)
- Clang>=19
- glibc 2.35+ or musl 1.2.4+
- macOS (ARM64): macOS Sonoma (14)+ with GCC>=14 (via Homebrew)
From version 0.1 onwards (before 1.0.0), all high-level public API that the average user is expected to interact with is considered stable. This includes basically everything, except what is in the rdf4cpp::storage and rdf4cpp::datatypes::registry namespaces. Should we ever break anything in these high-level interfaces, we will bump the minor version (for example, from 0.1.0 to 0.2.0).
ABI stability is not guaranteed.
The POBR (Persisted Object Binary Representation) version tracks on-disk format stability (e.g., with allocators like Metall). This includes everything in rdf4cpp::storage::identifiers but nothing else. The current POBR version can be retrieved via rdf4cpp::pobr_version.