<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.11.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Building</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign">
<div id="projectname">mi-malloc<span id="projectnumber"> 1.8/2.1</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
<input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(0); });
</script>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(function(){initNavTree('build.html',''); initResizable(true); });
</script>
<div id="doc-content">
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div><div class="header">
<div class="headertitle"><div class="title">Building</div></div>
</div>
<div class="contents">
<div class="textblock"><p>Checkout the sources from GitHub: </p><div class="fragment"><div class="line">git clone https:<span class="comment">//github.com/microsoft/mimalloc</span></div>
</div><h2>Windows</h2>
<p>Open <code>ide/vs2022/mimalloc.sln</code> in Visual Studio 2022 and build. The <code>mimalloc-lib</code> project builds a static library (in <code>out/msvc-x64</code>), while the <code>mimalloc-override-dll</code> project builds a DLL for overriding malloc in the entire program.</p>
<h2>Linux, macOS, BSD, etc.</h2>
<p>We use <a href="https://cmake.org"><code>cmake</code></a> as the build system:</p>
<div class="fragment"><div class="line">> mkdir -p out/release</div>
<div class="line">> cd out/release</div>
<div class="line">> cmake ../..</div>
<div class="line">> make</div>
</div><p> This builds the library as a shared (dynamic) library (<code>.so</code> or <code>.dylib</code>), a static library (<code>.a</code>), and as a single object file (<code>.o</code>).</p>
<p><code>> sudo make install</code> (install the library and header files in <code>/usr/local/lib</code> and <code>/usr/local/include</code>)</p>
<p>You can build the debug version which does many internal checks and maintains detailed statistics as:</p>
<div class="fragment"><div class="line">> mkdir -p out/debug</div>
<div class="line">> cd out/debug</div>
<div class="line">> cmake -DCMAKE_BUILD_TYPE=Debug ../..</div>
<div class="line">> make</div>
</div><p>This will name the shared library as <code>libmimalloc-debug.so</code>.</p>
<p>Finally, you can build a <em>secure</em> version that uses guard pages, encrypted free lists, etc., as:</p>
<div class="fragment"><div class="line">> mkdir -p out/secure</div>
<div class="line">> cd out/secure</div>
<div class="line">> cmake -DMI_SECURE=ON ../..</div>
<div class="line">> make</div>
</div><p>This will name the shared library as <code>libmimalloc-secure.so</code>. Use <code>cmake ../.. -LH</code> to see all the available build options.</p>
<p>The examples use the default compiler. If you like to use another, use:</p>
<div class="fragment"><div class="line">> CC=clang CXX=clang++ cmake ../..</div>
</div><h2>Cmake with Visual Studio</h2>
<p>You can also use cmake on Windows. Open a Visual Studio 2022 development prompt and invoke <code>cmake</code> with the right <a href="https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2017%202022.html">generator</a> and architecture, like:</p>
<div class="fragment"><div class="line">> cmake ..\.. -G <span class="stringliteral">"Visual Studio 17 2022"</span> -A x64 -DMI_OVERRIDE=ON</div>
</div><p>The cmake build type is specified when actually building, for example:</p>
<div class="fragment"><div class="line">> cmake --build . --config=Release</div>
</div><p>You can also install the <a href="https://learn.microsoft.com/en-us/cpp/build/clang-support-msbuild?view=msvc-170#install-1">LLVM toolset</a> on Windows to build with the <code>clang-cl</code> compiler directly:</p>
<div class="fragment"><div class="line">> cmake ../.. -G <span class="stringliteral">"Visual Studio 17 2022"</span> -T ClangCl</div>
</div><h2>Single Source</h2>
<p>You can also directly build the single <code>src/static.c</code> file as part of your project without needing <code>cmake</code> at all. Make sure to also add the mimalloc <code>include</code> directory to the include path. </p>
</div></div>
</div>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.11.0 </li>
</ul>
</div>
</body>
</html>