SVG libraries for C/C++
For C and C++ there are 3 common choices, from most complete to smallest:
- librsvg is the GNOME SVG renderer, used by GIMP, ImageMagick, libvips and Wikipedia. It supports most of SVG 1.1 and parts of SVG 2, including CSS, filters and text. It draws to a Cairo context, so it can produce PNG, PDF, PostScript or draw on screen. It is written in Rust with a C API, needs Cairo, Pango and GLib, and is LGPL.
- LunaSVG is a small C++ renderer (MIT) with its own rasterizer (plutovg). It supports the static parts of SVG 1.1 and SVG Tiny 1.2 except filters, has a DOM for changing attributes, CSS stylesheets and hit testing. Good for apps and games that need icons without a big dependency.
- NanoSVG is a single header (zlib license) that parses SVG into cubic Bézier paths, plus an optional rasterizer for flat-filled shapes. Use it when you want the geometry (for a game, CNC or plotter) or to bake simple icons; it isn’t a full renderer.
Pick librsvg when correctness matters (user files, server-side conversion); LunaSVG for embedded rendering with few dependencies; NanoSVG for geometry. resvg also has a C API if you can build Rust code.
- librsvg librsvg is the GNOME SVG rendering library with a C API. How to install it, render SVG to PNG and PDF with Cairo, get the intrinsic size, apply CSS.
- LunaSVG LunaSVG is a small MIT-licensed C++ library that renders SVG to bitmaps. How to build it, convert SVG to PNG, render at a size, apply CSS, change attributes.
- NanoSVG NanoSVG is a single-header C library that parses SVG into cubic Bézier paths, with a simple rasterizer. How to add it, read shapes and paths.