Skip to main content
This guide covers building libmem from source on all supported platforms.

Prerequisites

1

Install Windows SDK

Download and install the Windows SDK for your version:
2

Install Python 3

Download and install Python 3:
3

Install Visual Studio

Install Visual Studio 2022 or newer with:
  • C++ support
  • CMake tools
You can install only the Visual Studio Build Tools if you don’t want the full IDE.
4

Install Git Bash

Download and install Git Bash
5

Add to PATH (Optional)

Run a Visual Studio Developer Command Prompt (or x64 Native Tools Command Prompt for VS 2022 for 64-bit) as Administrator and run:
setx PATH "%PATH%;%ProgramFiles%\libmem\include;%ProgramFiles%\libmem\lib"
Watch for your PATH size limit when adding directories!

Build and Install

Windows: Run the following commands in Git Bash.Linux/FreeBSD: Run the following commands in a terminal.
1

Clone the repository

Clone the libmem repository with all submodules:
git clone --recursive --depth 1 https://github.com/rdbo/libmem
The --recursive flag ensures all submodules (capstone, keystone, LIEF, etc.) are cloned. The --depth 1 flag creates a shallow clone to save bandwidth.
2

Navigate to the repository

cd libmem
3

Generate the CMake cache

Create a build directory and generate the build files:
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-fpermissive -DCMAKE_EXPORT_COMPILE_COMMANDS=1
CMake Options:
  • CMAKE_BUILD_TYPE=Release - Build in release mode with optimizations
  • CMAKE_CXX_FLAGS=-fpermissive - Allow permissive C++ compilation
  • CMAKE_EXPORT_COMPILE_COMMANDS=1 - Export compile commands for IDE support
You can customize the build with these options:
# Build tests
cmake .. -DLIBMEM_BUILD_TESTS=ON

# Build static library instead of shared
cmake .. -DLIBMEM_BUILD_STATIC=ON

# Force a specific architecture
cmake .. -DLIBMEM_ARCH=x86_64

# Enable deep testing features
cmake .. -DLIBMEM_DEEP_TESTS=ON
4

Compile libmem

nmake
5

Install libmem

Run as Administrator (Windows) or root (Linux/FreeBSD)
Run in an Administrator Command Prompt:
nmake install
This installs libmem to C:\Program Files\libmem\ by default.

Build Outputs

After building, you’ll find the following files in the build directory:
  • libmem.dll - Dynamic link library
  • libmem.lib - Import library for linking
  • libmem.exp - Export file

Using the Built Library

After installation, follow the language-specific usage instructions:

C/C++

Add the include directive to your source code:
#include <libmem/libmem.h>   /* C/C++ */
#include <libmem/libmem.hpp> /* Modern C++ */
Link against the library:
gcc myprogram.c -llibmem -o myprogram
g++ myprogram.cpp -llibmem -o myprogram

Rust

Set the LIBMEM_DIR environment variable to point to your installation:
export LIBMEM_DIR=/usr  # Linux/FreeBSD
set LIBMEM_DIR=C:\Program Files\libmem  # Windows
Then add to Cargo.toml:
[dependencies]
libmem = { version = "5", features = [] }  # Disable auto-fetch

Python

Set the LIBDIR environment variable:
export LIBDIR=/usr  # Linux/FreeBSD
set LIBDIR=C:\Program Files\libmem  # Windows
Then install the Python package:
pip install libmem

Troubleshooting

Windows

Make sure you’re running the command in a Visual Studio Developer Command Prompt, not a regular Command Prompt.
Ensure Python is in your PATH. Re-install Python and check the “Add Python to PATH” option.
Install the appropriate Windows SDK for your Windows version. CMake will report which components are missing.

Linux/FreeBSD

Make sure to run sudo make install with root privileges.
Install the linux-headers or kernel-devel package for your distribution.
If you get errors about missing submodules, run:
git submodule update --init --recursive

Testing the Build

You can build and run the tests to verify your installation:
mkdir build
cd build
cmake .. -DLIBMEM_BUILD_TESTS=ON
make        # or nmake on Windows
./tests     # or tests.exe on Windows

Next Steps

Now that you’ve built and installed libmem from source, head to the Quickstart guide to start using it in your projects.

Build docs developers (and LLMs) love