1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Getting Started with the LLVM System using Microsoft Visual Studio — LLVM 13 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="LLVM Programmer’s Manual" href="ProgrammersManual.html" />
<link rel="prev" title="Getting Started with the LLVM System" href="GettingStarted.html" />
<style type="text/css">
table.right { float: right; margin-left: 20px; }
table.right td { border: 1px solid #ccc; }
</style>
</head><body>
<div class="logo">
<a href="index.html">
<img src="_static/logo.png"
alt="LLVM Logo" width="250" height="88"/></a>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="ProgrammersManual.html" title="LLVM Programmer’s Manual"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="GettingStarted.html" title="Getting Started with the LLVM System"
accesskey="P">previous</a> |</li>
<li><a href="https://llvm.org/">LLVM Home</a> | </li>
<li><a href="index.html">Documentation</a>»</li>
<li class="nav-item nav-item-1"><a href="GettingStartedTutorials.html" accesskey="U">Getting Started/Tutorials</a> »</li>
<li class="nav-item nav-item-this"><a href="">Getting Started with the LLVM System using Microsoft Visual Studio</a></li>
</ul>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3>Documentation</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/GettingStartedTutorials.html">Getting Started/Tutorials</a></li>
<li><a href="https://llvm.org/docs/UserGuides.html">User Guides</a></li>
<li><a href="https://llvm.org/docs/Reference.html">Reference</a></li>
</ul>
<h3>Getting Involved</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/Contributing.html">Contributing to LLVM</a></li>
<li><a href="https://llvm.org/docs/HowToSubmitABug.html">Submitting Bug Reports</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#mailing-lists">Mailing Lists</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#irc">IRC</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#meetups-and-social-events">Meetups and Social Events</a></li>
</ul>
<h3>Additional Links</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/FAQ.html">FAQ</a></li>
<li><a href="https://llvm.org/docs/Lexicon.html">Glossary</a></li>
<li><a href="https://llvm.org/pubs">Publications</a></li>
<li><a href="https://github.com/llvm/llvm-project//">Github Repository</a></li>
</ul>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/GettingStartedVS.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="getting-started-with-the-llvm-system-using-microsoft-visual-studio">
<h1>Getting Started with the LLVM System using Microsoft Visual Studio<a class="headerlink" href="#getting-started-with-the-llvm-system-using-microsoft-visual-studio" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#overview" id="id3">Overview</a></p></li>
<li><p><a class="reference internal" href="#requirements" id="id4">Requirements</a></p>
<ul>
<li><p><a class="reference internal" href="#hardware" id="id5">Hardware</a></p></li>
<li><p><a class="reference internal" href="#software" id="id6">Software</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#getting-started" id="id7">Getting Started</a></p></li>
<li><p><a class="reference internal" href="#alternatives-to-manual-installation" id="id8">Alternatives to manual installation</a></p></li>
<li><p><a class="reference internal" href="#next-steps" id="id9">Next steps</a></p>
<ul>
<li><p><a class="reference internal" href="#test-llvm-on-the-command-line" id="id10">Test LLVM on the command line:</a></p></li>
<li><p><a class="reference internal" href="#build-the-llvm-suite" id="id11">Build the LLVM Suite:</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#links" id="id12">Links</a></p></li>
</ul>
</div>
<div class="section" id="overview">
<h2><a class="toc-backref" href="#id3">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>Welcome to LLVM on Windows! This document only covers LLVM on Windows using
Visual Studio, not WSL, mingw or cygwin. In order to get started, you first need
to know some basic information.</p>
<p>There are many different projects that compose LLVM. The first piece is the
LLVM suite. This contains all of the tools, libraries, and header files needed
to use LLVM. It contains an assembler, disassembler, bitcode analyzer and
bitcode optimizer. It also contains basic regression tests that can be used to
test the LLVM tools and the Clang front end.</p>
<p>The second piece is the <a class="reference external" href="https://clang.llvm.org/">Clang</a> front end. This
component compiles C, C++, Objective C, and Objective C++ code into LLVM
bitcode. Clang typically uses LLVM libraries to optimize the bitcode and emit
machine code. LLVM fully supports the COFF object file format, which is
compatible with all other existing Windows toolchains.</p>
<p>There are more LLVM projects which this document does not discuss.</p>
</div>
<div class="section" id="requirements">
<h2><a class="toc-backref" href="#id4">Requirements</a><a class="headerlink" href="#requirements" title="Permalink to this headline">¶</a></h2>
<p>Before you begin to use the LLVM system, review the requirements given
below. This may save you some trouble by knowing ahead of time what hardware
and software you will need.</p>
<div class="section" id="hardware">
<h3><a class="toc-backref" href="#id5">Hardware</a><a class="headerlink" href="#hardware" title="Permalink to this headline">¶</a></h3>
<p>Any system that can adequately run Visual Studio 2017 is fine. The LLVM
source tree including the git index consumes approximately 3GB.
Object files, libraries and executables consume approximately 5GB in
Release mode and much more in Debug mode. SSD drive and >16GB RAM are
recommended.</p>
</div>
<div class="section" id="software">
<h3><a class="toc-backref" href="#id6">Software</a><a class="headerlink" href="#software" title="Permalink to this headline">¶</a></h3>
<p>You will need <a class="reference external" href="https://visualstudio.microsoft.com/">Visual Studio</a> 2017 or
higher, with the latest Update installed. Visual Studio Community Edition
suffices.</p>
<p>You will also need the <a class="reference external" href="http://www.cmake.org/">CMake</a> build system since it
generates the project files you will use to build with. CMake is bundled with
Visual Studio 2019 so separate installation is not required.</p>
<p>If you would like to run the LLVM tests you will need <a class="reference external" href="http://www.python.org/">Python</a>. Version 3.6 and newer are known to work. You can
install Python with Visual Studio 2019, from the Microsoft store or from
the <a class="reference external" href="http://www.python.org/">Python web site</a>. We recommend the latter since it
allows you to to adjust installation options.</p>
<p>You will need <a class="reference external" href="https://git-scm.com/">Git for Windows</a> with bash tools, too.
Git for Windows is also bundled with Visual Studio 2019.</p>
</div>
</div>
<div class="section" id="getting-started">
<h2><a class="toc-backref" href="#id7">Getting Started</a><a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h2>
<p>Here’s the short story for getting up and running quickly with LLVM.
These instruction were tested with Visual Studio 2019 and Python 3.9.6:</p>
<ol class="arabic">
<li><p>Download and install <a class="reference external" href="https://visualstudio.microsoft.com/">Visual Studio</a>.</p></li>
<li><p>In the Visual Studio installer, Workloads tab, select the
<strong>Desktop development with C++</strong> workload. Under Individual components tab,
select <strong>Git for Windows</strong>.</p></li>
<li><p>Complete the Visual Studio installation.</p></li>
<li><p>Download and install the latest <a class="reference external" href="http://www.python.org/">Python 3 release</a>.</p></li>
<li><p>In the first install screen, select both <strong>Install launcher for all users</strong>
and <strong>Add Python to the PATH</strong>. This will allow installing psutil for all
users for the regression tests and make Python available from the command
line.</p></li>
<li><p>In the second install screen, select (again) <strong>Install for all users</strong> and
if you want to develop <a class="reference external" href="https://lldb.llvm.org/">lldb</a>, selecting
<strong>Download debug binaries</strong> is useful.</p></li>
<li><p>Complete the Python installation.</p></li>
<li><dl class="simple">
<dt>Run a “Developer Command Prompt for VS 2019” <strong>as administrator</strong>. This command</dt><dd><p>prompt provides correct path and environment variables to Visual Studio and
the installed tools.</p>
</dd>
</dl>
</li>
<li><p>In the terminal window, type the commands:</p>
<div class="highlight-bat notranslate"><div class="highlight"><pre><span></span>c<span class="p">:</span>
<span class="k">cd</span> \
</pre></div>
</div>
</li>
</ol>
<blockquote>
<div><p>You may install the llvm sources in other location than <code class="docutils literal notranslate"><span class="pre">c:\llvm</span></code> but do not
install into a path containing spaces (e.g. <code class="docutils literal notranslate"><span class="pre">c:\Documents</span> <span class="pre">and</span> <span class="pre">Settings\...</span></code>)
as it will fail.</p>
</div></blockquote>
<ol class="arabic" start="10">
<li><p>Register the Microsoft Debug Interface Access (DIA) DLLs</p>
<div class="highlight-bat notranslate"><div class="highlight"><pre><span></span>regsvr32 <span class="s2">"</span><span class="nv">%VSINSTALLDIR%</span><span class="s2">\DIA SDK\bin\msdia140.dll"</span>
regsvr32 <span class="s2">"</span><span class="nv">%VSINSTALLDIR%</span><span class="s2">\DIA SDK\bin\amd64\msdia140.dll"</span>
</pre></div>
</div>
</li>
</ol>
<blockquote>
<div><p>The DIA library is required for LLVM PDB tests and
<a class="reference external" href="https://lldb.llvm.org/resources/build.html">LLDB development</a>.</p>
</div></blockquote>
<ol class="arabic" start="11">
<li><p>Install psutil and obtain LLVM source code:</p>
<div class="highlight-bat notranslate"><div class="highlight"><pre><span></span>pip install psutil
git clone https://github.com/llvm/llvm-project.git llvm
</pre></div>
</div>
</li>
</ol>
<blockquote>
<div><p>Instead of <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">clone</span></code> you may download a compressed source distribution
from the <a class="reference external" href="https://github.com/llvm/llvm-project/releases">releases page</a>.
Select the last link: <code class="docutils literal notranslate"><span class="pre">Source</span> <span class="pre">code</span> <span class="pre">(zip)</span></code> and unpack the downloaded file using
Windows Explorer built-in zip support or any other unzip tool.</p>
</div></blockquote>
<ol class="arabic" start="12">
<li><p>Finally, configure LLVM using CMake:</p>
<div class="highlight-bat notranslate"><div class="highlight"><pre><span></span>cmake -S llvm\llvm -B build -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=X86 -Thost=x64
<span class="k">exit</span>
</pre></div>
</div>
</li>
</ol>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">LLVM_ENABLE_PROJECTS</span></code> specifies any additional LLVM projects you want to
build while <code class="docutils literal notranslate"><span class="pre">LLVM_TARGETS_TO_BUILD</span></code> selects the compiler targets. If
<code class="docutils literal notranslate"><span class="pre">LLVM_TARGETS_TO_BUILD</span></code> is omitted by default all targets are built
slowing compilation and using more disk space.
See the <a class="reference internal" href="CMake.html"><span class="doc">LLVM CMake guide</span></a> for detailed information about
how to configure the LLVM build.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">cmake</span></code> command line tool is bundled with Visual Studio but its GUI is
not. You may install <a class="reference external" href="http://www.cmake.org/">CMake</a> to use its GUI to change
CMake variables or modify the above command line.</p>
<ul class="simple">
<li><p>Once CMake is installed then the simplest way is to just start the
CMake GUI, select the directory where you have LLVM extracted to, and
the default options should all be fine. One option you may really
want to change, regardless of anything else, might be the
<code class="docutils literal notranslate"><span class="pre">CMAKE_INSTALL_PREFIX</span></code> setting to select a directory to INSTALL to
once compiling is complete, although installation is not mandatory for
using LLVM. Another important option is <code class="docutils literal notranslate"><span class="pre">LLVM_TARGETS_TO_BUILD</span></code>,
which controls the LLVM target architectures that are included on the
build.</p></li>
<li><p>CMake generates project files for all build types. To select a specific
build type, use the Configuration manager from the VS IDE or the
<code class="docutils literal notranslate"><span class="pre">/property:Configuration</span></code> command line option when using MSBuild.</p></li>
<li><p>By default, the Visual Studio project files generated by CMake use the
32-bit toolset. If you are developing on a 64-bit version of Windows and
want to use the 64-bit toolset, pass the <code class="docutils literal notranslate"><span class="pre">-Thost=x64</span></code> flag when
generating the Visual Studio solution. This requires CMake 3.8.0 or later.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="13">
<li><p>Start Visual Studio and select configuration:</p></li>
</ol>
<blockquote>
<div><p>In the directory you created the project files will have an <code class="docutils literal notranslate"><span class="pre">llvm.sln</span></code>
file, just double-click on that to open Visual Studio. The default Visual
Studio configuration is <strong>Debug</strong> which is slow and generates a huge amount
of debug information on disk. For now, we recommend selecting <strong>Release</strong>
configuration for the LLVM project which will build the fastest or
<strong>RelWithDebInfo</strong> which is also several time larger than Release.
Another technique is to build all of LLVM in Release mode and change
compiler flags, disabling optimization and enabling debug information, only
for specific librares or source files you actually need to debug.</p>
</div></blockquote>
<ol class="arabic simple" start="14">
<li><p>Test LLVM in Visual Studio:</p></li>
</ol>
<blockquote>
<div><p>You can run LLVM tests by merely building the project “check-all”. The test
results will be shown in the VS output window. Once the build succeeds, you
have verified a working LLVM development environment!</p>
<p>You should not see any unexpected failures, but will see many unsupported
tests and expected failures:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>114>Testing Time: 1124.66s
114> Skipped : 39
114> Unsupported : 21649
114> Passed : 51615
114> Expectedly Failed: 93
========== Build: 114 succeeded, 0 failed, 321 up-to-date, 0 skipped ==========``
</pre></div>
</div>
</div></blockquote>
</div>
<div class="section" id="alternatives-to-manual-installation">
<h2><a class="toc-backref" href="#id8">Alternatives to manual installation</a><a class="headerlink" href="#alternatives-to-manual-installation" title="Permalink to this headline">¶</a></h2>
<p>Instead of the steps above, to simplify the installation procedure you can use
<a class="reference external" href="https://chocolatey.org/">Chocolatey</a> as package manager.
After the <a class="reference external" href="https://chocolatey.org/install">installation</a> of Chocolatey,
run these commands in an admin shell to install the required tools:</p>
<div class="highlight-bat notranslate"><div class="highlight"><pre><span></span>choco install -y git cmake python3
pip3 install psutil
</pre></div>
</div>
<p>There is also a Windows
<a class="reference external" href="https://github.com/llvm/llvm-zorg/blob/main/buildbot/google/docker/windows-base-vscode2019/Dockerfile">Dockerfile</a>
with the entire build tool chain. This can be used to test the build with a
tool chain different from your host installation or to create build servers.</p>
</div>
<div class="section" id="next-steps">
<h2><a class="toc-backref" href="#id9">Next steps</a><a class="headerlink" href="#next-steps" title="Permalink to this headline">¶</a></h2>
<ol class="arabic simple">
<li><p>Read the documentation.</p></li>
<li><p>Seriously, read the documentation.</p></li>
<li><p>Remember that you were warned twice about reading the documentation.</p></li>
</ol>
<div class="section" id="test-llvm-on-the-command-line">
<h3><a class="toc-backref" href="#id10">Test LLVM on the command line:</a><a class="headerlink" href="#test-llvm-on-the-command-line" title="Permalink to this headline">¶</a></h3>
<p>The LLVM tests can be run by changing directory to the llvm source
directory and running:</p>
<div class="highlight-bat notranslate"><div class="highlight"><pre><span></span>c<span class="p">:</span><span class="nl">\llvm</span><span class="c1">> python ..\build\Release\bin\llvm-lit.py llvm\test</span>
</pre></div>
</div>
<p>This example assumes that Python is in your PATH variable, which would be
after <strong>Add Python to the PATH</strong> was selected during Python installation.
If you had opened a command window prior to Python installation, you would
have to close and reopen it to get the updated PATH.</p>
<p>A specific test or test directory can be run with:</p>
<div class="highlight-bat notranslate"><div class="highlight"><pre><span></span>c<span class="p">:</span><span class="nl">\llvm</span><span class="c1">> python ..\build\Release\bin\llvm-lit.py llvm\test\Transforms\Util</span>
</pre></div>
</div>
</div>
<div class="section" id="build-the-llvm-suite">
<h3><a class="toc-backref" href="#id11">Build the LLVM Suite:</a><a class="headerlink" href="#build-the-llvm-suite" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p>The projects may still be built individually, but to build them all do
not just select all of them in batch build (as some are meant as
configuration projects), but rather select and build just the
<code class="docutils literal notranslate"><span class="pre">ALL_BUILD</span></code> project to build everything, or the <code class="docutils literal notranslate"><span class="pre">INSTALL</span></code> project,
which first builds the <code class="docutils literal notranslate"><span class="pre">ALL_BUILD</span></code> project, then installs the LLVM
headers, libs, and other useful things to the directory set by the
<code class="docutils literal notranslate"><span class="pre">CMAKE_INSTALL_PREFIX</span></code> setting when you first configured CMake.</p></li>
<li><p>The Fibonacci project is a sample program that uses the JIT. Modify the
project’s debugging properties to provide a numeric command line argument
or run it from the command line. The program will print the
corresponding fibonacci value.</p></li>
</ul>
</div>
</div>
<div class="section" id="links">
<h2><a class="toc-backref" href="#id12">Links</a><a class="headerlink" href="#links" title="Permalink to this headline">¶</a></h2>
<p>This document is just an <strong>introduction</strong> to how to use LLVM to do some simple
things… there are many more interesting and complicated things that you can
do that aren’t documented here (but we’ll gladly accept a patch if you want to
write something up!). For more information about LLVM, check out:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://llvm.org/">LLVM homepage</a></p></li>
<li><p><a class="reference external" href="https://llvm.org/doxygen/">LLVM doxygen tree</a></p></li>
<li><p>Additional information about the LLVM directory structure and tool chain
can be found on the main <a class="reference internal" href="GettingStarted.html"><span class="doc">Getting Started with the LLVM System</span></a> page.</p></li>
<li><p>If you are having problems building or using LLVM, or if you have any other
general questions about LLVM, please consult the
<a class="reference internal" href="FAQ.html"><span class="doc">Frequently Asked Questions</span></a> page.</p></li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="ProgrammersManual.html" title="LLVM Programmer’s Manual"
>next</a> |</li>
<li class="right" >
<a href="GettingStarted.html" title="Getting Started with the LLVM System"
>previous</a> |</li>
<li><a href="https://llvm.org/">LLVM Home</a> | </li>
<li><a href="index.html">Documentation</a>»</li>
<li class="nav-item nav-item-1"><a href="GettingStartedTutorials.html" >Getting Started/Tutorials</a> »</li>
<li class="nav-item nav-item-this"><a href="">Getting Started with the LLVM System using Microsoft Visual Studio</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2003-2021, LLVM Project.
Last updated on 2021-09-18.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.5.4.
</div>
</body>
</html>
|