blob: 96b7bfe928b44fdb322af4c296aaafc3810172c8 [file] [log] [blame]
Jeff Cohen7a4f03d2005-01-31 05:42:10 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>Getting Started with LLVM System for Microsoft Visual Studio</title>
7 <link rel="stylesheet" href="llvm.css" type="text/css">
8</head>
9<body>
10
11<div class="doc_title">
12 Getting Started with the LLVM System using Microsoft Visual Studio
13</div>
14
15<ul>
16 <li><a href="#overview">Overview</a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000017 <li><a href="#requirements">Requirements</a>
18 <ol>
19 <li><a href="#hardware">Hardware</a>
20 <li><a href="#software">Software</a>
21 </ol></li>
Oscar Fuentes96b5f712010-09-17 02:17:13 +000022 <li><a href="#quickstart">Getting Started</a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000023 <li><a href="#tutorial">An Example Using the LLVM Tool Chain</a>
24 <li><a href="#problems">Common Problems</a>
25 <li><a href="#links">Links</a>
26</ul>
27
28<div class="doc_author">
Michael J. Spencere1630da2010-09-17 06:33:20 +000029 <p>Written by:
Jeff Cohenb9a47d12005-02-01 15:59:28 +000030 <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000031 </p>
32</div>
33
34
35<!-- *********************************************************************** -->
36<div class="doc_section">
37 <a name="overview"><b>Overview</b></a>
38</div>
39<!-- *********************************************************************** -->
40
41<div class="doc_text">
42
Michael J. Spenceraf3874d2010-09-18 08:32:32 +000043 <p>Welcome to LLVM on Windows! This document only covers LLVM on Windows using
44 Visual Studio, not mingw or cygwin. In order to get started, you first need to
45 know some basic information.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000046
Michael J. Spencere1630da2010-09-17 06:33:20 +000047 <p>There are many different projects that compose LLVM. The first is the LLVM
48 suite. This contains all of the tools, libraries, and header files needed to
49 use the low level virtual machine. It contains an assembler, disassembler,
50 bitcode analyzer and bitcode optimizer. It also contains a test suite that can
51 be used to test the LLVM tools.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000052
Michael J. Spencere1630da2010-09-17 06:33:20 +000053 <p>Another useful project on Windows is
54 <a href="http://clang.llvm.org/">clang</a>. Clang is a C family
Michael J. Spenceraf3874d2010-09-18 08:32:32 +000055 ([Objective]C/C++) compiler. Clang mostly works on Windows, but does not
Michael J. Spencere1630da2010-09-17 06:33:20 +000056 currently understand all of the Microsoft extensions to C and C++. Because of
57 this, clang cannot parse the C++ standard library included with Visual Studio,
58 nor parts of the Windows Platform SDK. However, most standard C programs do
59 compile. Clang can be used to emit bitcode, directly emit object files or
60 even linked executables using Visual Studio's <tt>link.exe</tt></p>
61
Michael J. Spenceraf3874d2010-09-18 08:32:32 +000062 <p>The large LLVM test suite cannot be run on the Visual Studio port at this
Michael J. Spencere1630da2010-09-17 06:33:20 +000063 time.</p>
64
65 <p>Most of the tools build and work. <tt>bugpoint</tt> does build, but does
66 not work.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000067
68 <p>Additional information about the LLVM directory structure and tool chain
69 can be found on the main <a href="GettingStarted.html">Getting Started</a>
Nick Lewycky28ea4f62008-12-08 00:45:02 +000070 page.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000071
72</div>
73
74<!-- *********************************************************************** -->
75<div class="doc_section">
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000076 <a name="requirements"><b>Requirements</b></a>
77</div>
78<!-- *********************************************************************** -->
79
80<div class="doc_text">
81
82 <p>Before you begin to use the LLVM system, review the requirements given
83 below. This may save you some trouble by knowing ahead of time what hardware
84 and software you will need.</p>
85
86</div>
87
88<!-- ======================================================================= -->
89<div class="doc_subsection">
90 <a name="hardware"><b>Hardware</b></a>
91</div>
92
93<div class="doc_text">
94
Michael J. Spencere1630da2010-09-17 06:33:20 +000095 <p>Any system that can adequately run Visual Studio .NET 2005 SP1 is fine.
Nick Lewycky28ea4f62008-12-08 00:45:02 +000096 The LLVM source tree and object files, libraries and executables will consume
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000097 approximately 3GB.</p>
98
99</div>
100
101<!-- ======================================================================= -->
102<div class="doc_subsection"><a name="software"><b>Software</b></a></div>
103<div class="doc_text">
104
Nick Lewycky28ea4f62008-12-08 00:45:02 +0000105 <p>You will need Visual Studio .NET 2005 SP1 or higher. The VS2005 SP1
106 beta and the normal VS2005 still have bugs that are not completely
Michael J. Spencere1630da2010-09-17 06:33:20 +0000107 compatible. Earlier versions of Visual Studio do not support the C++ standard
108 well enough and will not work.</p>
109
Nick Lewycky28ea4f62008-12-08 00:45:02 +0000110 <p>You will also need the <a href="http://www.cmake.org/">CMake</a> build
111 system since it generates the project files you will use to build with.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000112
Michael J. Spencere1630da2010-09-17 06:33:20 +0000113 <p>If you would like to run the LLVM tests you will need
114 <a href="http://www.python.org/">Python</a>. Versions 2.4-2.7 are known to
115 work.</p>
116
117 <p>Do not install the LLVM directory tree into a path containing spaces (e.g.
Chris Lattnerc2bb1232007-11-14 07:04:44 +0000118 C:\Documents and Settings\...) as the configure step will fail.</p>
119
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000120</div>
121
122<!-- *********************************************************************** -->
123<div class="doc_section">
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000124 <a name="quickstart"><b>Getting Started</b></a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000125</div>
126<!-- *********************************************************************** -->
127
128<div class="doc_text">
129
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000130<p>Here's the short story for getting up and running quickly with LLVM:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000131
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000132<ol>
133 <li>Read the documentation.</li>
134 <li>Seriously, read the documentation.</li>
135 <li>Remember that you were warned twice about reading the documentation.</li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000136
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000137 <li>Get the Source Code
138 <ul>
139 <li>With the distributed files:
140 <ol>
141 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
142 <li><tt>gunzip --stdout llvm-<i>version</i>.tar.gz | tar -xvf -</tt>
143 <i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or use WinZip</i>
144 <li><tt>cd llvm</tt></li>
145 </ol></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000146
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000147 <li>With anonymous Subversion access:
148 <ol>
149 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt></li>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000150 <li><tt>svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</tt></li>
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000151 <li><tt>cd llvm</tt></li>
152 </ol></li>
153 </ul></li>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000154
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000155 <li> Use <a href="http://www.cmake.org/">CMake</a> to generate up-to-date
156 project files:
157 <ul>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000158 <li>Once CMake is installed then the simplest way is to just start the
159 CMake GUI, select the directory where you have LLVM extracted to, and the
160 default options should all be fine. One option you may really want to
161 change, regardless of anything else, might be the CMAKE_INSTALL_PREFIX
162 setting to select a directory to INSTALL to once compiling is complete,
163 although installation is not mandatory for using LLVM. Another important
164 option is LLVM_TARGETS_TO_BUILD, which controls the LLVM target
165 architectures that are included on the build.
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000166 <li>See the <a href="CMake.html">LLVM CMake guide</a> for
167 detailed information about how to configure the LLVM
168 build.</li>
169 </ul>
170 </li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000171
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000172 <li>Start Visual Studio
173 <ul>
174 <li>In the directory you created the project files will have
175 an <tt>llvm.sln</tt> file, just double-click on that to open
176 Visual Studio.</li>
177 </ul></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000178
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000179 <li>Build the LLVM Suite:
180 <ul>
181 <li>The projects may still be built individually, but
182 to build them all do not just select all of them in batch build (as some
183 are meant as configuration projects), but rather select and build just
184 the ALL_BUILD project to build everything, or the INSTALL project, which
185 first builds the ALL_BUILD project, then installs the LLVM headers, libs,
186 and other useful things to the directory set by the CMAKE_INSTALL_PREFIX
187 setting when you first configured CMake.</li>
188 <li>The Fibonacci project is a sample program that uses the JIT.
189 Modify the project's debugging properties to provide a numeric
190 command line argument or run it from the command line. The
191 program will print the corresponding fibonacci value.</li>
192 </ul></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000193
Michael J. Spencere1630da2010-09-17 06:33:20 +0000194 <li>Test LLVM:
195 <ul>
196 <li>The LLVM tests can be run by <tt>cd</tt>ing to the llvm source directory
197 and running:
198
199<div class="doc_code">
200<pre>
201% llvm-lit test
202</pre>
203</div>
204
205 <p>Note that quite a few of these test will fail.</p>
206 </li>
207
208 <li>A specific test or test directory can be run with:</li>
209
210<div class="doc_code">
211<pre>
212% llvm-lit test/path/to/test
213</pre>
214</div>
215
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000216</ol>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000217
218</div>
219
220<!-- *********************************************************************** -->
221<div class="doc_section">
222 <a name="tutorial">An Example Using the LLVM Tool Chain</a>
223</div>
224<!-- *********************************************************************** -->
225
226<div class="doc_text">
227
228<ol>
Bill Wendling03c993a2007-09-22 09:39:19 +0000229 <li><p>First, create a simple C file, name it 'hello.c':</p>
230
231<div class="doc_code">
232<pre>
233#include &lt;stdio.h&gt;
234int main() {
235 printf("hello world\n");
236 return 0;
237}
238</pre></div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000239
Gabor Greif04367bf2007-07-06 22:07:22 +0000240 <li><p>Next, compile the C file into a LLVM bitcode file:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000241
Bill Wendling03c993a2007-09-22 09:39:19 +0000242<div class="doc_code">
243<pre>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000244% clang -c hello.c -emit-llvm -o hello.bc
Bill Wendling03c993a2007-09-22 09:39:19 +0000245</pre>
246</div>
247
248 <p>This will create the result file <tt>hello.bc</tt> which is the LLVM
249 bitcode that corresponds the the compiled program and the library
250 facilities that it required. You can execute this file directly using
251 <tt>lli</tt> tool, compile it to native assembly with the <tt>llc</tt>,
252 optimize or analyze it further with the <tt>opt</tt> tool, etc.</p>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000253
254 <p>Alternatively you can directly output an executable with clang with:
255 </p>
256
257<div class="doc_code">
258<pre>
259% clang hello.c -o hello.exe
260</pre>
261</div>
262
263 <p>The <tt>-o hello.exe</tt> is required because clang currently outputs
264 <tt>a.out</tt> when neither <tt>-o</tt> nor <tt>-c</tt> are given.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000265
Jeff Cohena0887342005-10-30 21:00:24 +0000266 <li><p>Run the program using the just-in-time compiler:</p>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000267
Bill Wendling03c993a2007-09-22 09:39:19 +0000268<div class="doc_code">
269<pre>
270% lli hello.bc
271</pre>
272</div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000273
274 <li><p>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
275 code:</p>
276
Bill Wendling03c993a2007-09-22 09:39:19 +0000277<div class="doc_code">
278<pre>
279% llvm-dis &lt; hello.bc | more
280</pre>
281</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000282
Michael J. Spencere1630da2010-09-17 06:33:20 +0000283 <li><p>Compile the program to object code using the LLC code generator:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000284
Bill Wendling03c993a2007-09-22 09:39:19 +0000285<div class="doc_code">
286<pre>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000287% llc -filetype=obj hello.bc
Bill Wendling03c993a2007-09-22 09:39:19 +0000288</pre>
289</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000290
Michael J. Spencere1630da2010-09-17 06:33:20 +0000291 <li><p>Link to binary using Microsoft link:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000292
Bill Wendling03c993a2007-09-22 09:39:19 +0000293<div class="doc_code">
294<pre>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000295% link hello.obj -defaultlib:libcmt
Bill Wendling03c993a2007-09-22 09:39:19 +0000296</pre>
297</div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000298
299 <li><p>Execute the native code program:</p>
300
Bill Wendling03c993a2007-09-22 09:39:19 +0000301<div class="doc_code">
302<pre>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000303% hello.exe
Bill Wendling03c993a2007-09-22 09:39:19 +0000304</pre>
305</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000306</ol>
307
308</div>
309
310<!-- *********************************************************************** -->
311<div class="doc_section">
312 <a name="problems">Common Problems</a>
313</div>
314<!-- *********************************************************************** -->
315
316<div class="doc_text">
317
318<p>If you are having problems building or using LLVM, or if you have any other
319general questions about LLVM, please consult the <a href="FAQ.html">Frequently
320Asked Questions</a> page.</p>
321
322</div>
323
324<!-- *********************************************************************** -->
325<div class="doc_section">
326 <a name="links">Links</a>
327</div>
328<!-- *********************************************************************** -->
329
330<div class="doc_text">
331
332<p>This document is just an <b>introduction</b> to how to use LLVM to do
333some simple things... there are many more interesting and complicated things
334that you can do that aren't documented here (but we'll gladly accept a patch
335if you want to write something up!). For more information about LLVM, check
336out:</p>
337
338<ul>
Reid Spencer05fe4b02006-03-14 05:39:39 +0000339 <li><a href="http://llvm.org/">LLVM homepage</a></li>
340 <li><a href="http://llvm.org/doxygen/">LLVM doxygen tree</a></li>
341 <li><a href="http://llvm.org/docs/Projects.html">Starting a Project
Bill Wendling03c993a2007-09-22 09:39:19 +0000342 that Uses LLVM</a></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000343</ul>
344
345</div>
346
347<!-- *********************************************************************** -->
348
349<hr>
350<address>
351 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000352 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000353 <a href="http://validator.w3.org/check/referer"><img
Misha Brukmanf00ddb02008-12-11 18:23:24 +0000354 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000355
Jeff Cohenb9a47d12005-02-01 15:59:28 +0000356 <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +0000357 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000358 Last modified: $Date$
359</address>
360</body>
361</html>