MeshLib provides native CMake integration support for Linux and macOS; for Windows see the Windows Integration Guide below. Example CMake configuration files are available to demonstrate how to link against the pre-built libraries. You can find these examples in the examples directory.
MeshLib requires CMake 3.18 or newer. If configuration or the build fails, see Troubleshooting in the C++ Setup Guide.
For a start, find the MeshLib package:
The Ubuntu .deb and the macOS .pkg install the package where CMake searches by default. For the portable Linux vcpkg build, pass the directory it was unpacked to:
MeshLib_DIR alone is not sufficient, since the bundled third-party libraries are looked up in the same directory.
Add both include directories from the installed MeshLib package to your project. In your CMake configuration (CMakeLists.txt):
MESHLIB_THIRDPARTY_INCLUDE_DIR is required, not optional: MeshLib's public headers include third-party headers directly — MRMesh/MRMeshFwd.h, pulled in by essentially every MeshLib header, includes <parallel_hashmap/phmap_fwd_decl.h>. Without it even a hello-world fails to compile.
Specify which MeshLib libraries to link with your project:
Or if you use the C API, instead link MeshLib::MeshLibC2:
The package defines the following targets, each guarded by the variable in parentheses. A distribution sets it to ON for every module it ships, and only those targets exist.
Putting the steps above together, this is a complete CMakeLists.txt that compiles, links and runs a program including <MRMesh/MRMesh.h>. The Linking Additional Third-Party Libraries section below is not needed for it:
For the main.cpp this expects, see Verify your setup in the C++ Setup Guide: a self-contained program that builds a mesh, checks it, saves it and returns non-zero on failure.
A C project is the same shape, linking MeshLib::MeshLibC2 instead. Note that it needs only MESHLIB_INCLUDE_DIR as the MRC* headers include no third-party header.
For the main.c, take one of the C code samples; Load and Save Meshes is the shortest.
Only if your own code links a third-party library bundled with MeshLib (rather than just using MeshLib's API), add the directory those libraries live in:
The MeshLib::* imported targets already carry the paths of the third-party libraries they need, so this line is not required by the example above. See the CMakeLists.txt in the examples directory for a working configuration.
MeshLib supports Windows via CMake, including integration with Visual Studio: ensure the CMake component is installed in your Visual Studio setup.
MeshLibDistClangCl_<version>.zip (and its -arm64 sibling) is a CMake install prefix, so find_package(MeshLib CONFIG REQUIRED) works with it as in the sections above. Extracted to C:/meshlib-built, point CMake at it and build your project in Release, the only configuration it ships:
To run the result, put C:/meshlib-built/install/bin on PATH or copy its DLLs next to your executable.
The MeshLibDistVS*.zip archives contain no CMake config files, so find_package(MeshLib CONFIG REQUIRED) fails at configure time. Point CMake at the extracted tree instead — assuming the archive was extracted to C:/meshlib-built as described in the C++ Setup Guide:
Finally, copy the runtime libraries next to your executable, as described in the C++ Setup Guide.
Building with a non-zero iterator debug level needs a different archive (MeshLibDist_*-IteratorDebug.zip), and the level your project compiles with has to agree with the one the archive was built with, or the build stops with fatal error C1189: _ITERATOR_DEBUG_LEVEL is inconsistent with MeshLib. An archive shipping install/include/MRMesh/config_dist.h declares its own level, so a Debug build against IteratorDebug needs no flags at all; the form below also covers older archives, where MR_ITERATOR_DEBUG_LEVEL has to be named explicitly:
To build MeshLib itself from source, install its dependencies with vcpkg as described in Installing the local build in the C++ Setup Guide, then configure from the repository root:
The triplet must be the one the dependencies were actually installed with. x64-windows-meshlib is install.bat's default, so it is the right value for Visual Studio 2026; on Visual Studio 2019 or 2022, step 4 of Installing the local build has you set VCPKG_DEFAULT_TRIPLET to x64-windows-vs2019-meshlib or x64-windows-vs2022-meshlib, so pass that same value here.