mi-malloc: Building
Checkout the sources from GitHub:
Windows
Open ide/vs2022/mimalloc.sln in Visual Studio 2022 and build. The mimalloc-lib project builds a static library (in out/msvc-x64), while the mimalloc-override-dll project builds a DLL for overriding malloc in the entire program.
Linux, macOS, BSD, etc.
We use cmake as the build system:
> mkdir -p out/release
> cd out/release
> cmake ../..
> make
This builds the library as a shared (dynamic) library (.so or .dylib), a static library (.a), and as a single object file (.o).
> sudo make install (install the library and header files in /usr/local/lib and /usr/local/include)
You can build the debug version which does many internal checks and maintains detailed statistics as:
> mkdir -p out/debug
> cd out/debug
> cmake -DCMAKE_BUILD_TYPE=Debug ../..
> make
This will name the shared library as libmimalloc-debug.so.
Finally, you can build a secure version that uses guard pages, encrypted free lists, etc., as:
> mkdir -p out/secure
> cd out/secure
> cmake -DMI_SECURE=ON ../..
> make
This will name the shared library as libmimalloc-secure.so. Use cmake ../.. -LH to see all the available build options.
The examples use the default compiler. If you like to use another, use:
> CC=clang CXX=clang++ cmake ../..
Cmake with Visual Studio
You can also use cmake on Windows. Open a Visual Studio 2022 development prompt and invoke cmake with the right generator and architecture, like:
> cmake ..\.. -G "Visual Studio 17 2022" -A x64 -DMI_OVERRIDE=ON
The cmake build type is specified when actually building, for example:
> cmake --build . --config=Release
You can also install the LLVM toolset on Windows to build with the clang-cl compiler directly:
> cmake ../.. -G "Visual Studio 17 2022" -T ClangCl
Single Source
You can also directly build the single src/static.c file as part of your project without needing cmake at all. Make sure to also add the mimalloc include directory to the include path.