blob: b0ed82409da245c47cce689605a3bfd3b89f1933 [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>
Daniel Dunbaradea4972012-04-19 20:20:34 +00007 <link rel="stylesheet" href="_static/llvm.css" type="text/css">
Jeff Cohen7a4f03d2005-01-31 05:42:10 +00008</head>
9<body>
10
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000011<h1>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000012 Getting Started with the LLVM System using Microsoft Visual Studio
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000013</h1>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000014
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">
NAKAMURA Takumib9a33632011-04-09 02:13:37 +000029 <p>Written by: <a href="http://llvm.org/">The LLVM Team</a></p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000030</div>
31
32
33<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000034<h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000035 <a name="overview"><b>Overview</b></a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000036</h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000037<!-- *********************************************************************** -->
38
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000039<div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000040
Michael J. Spenceraf3874d2010-09-18 08:32:32 +000041 <p>Welcome to LLVM on Windows! This document only covers LLVM on Windows using
42 Visual Studio, not mingw or cygwin. In order to get started, you first need to
43 know some basic information.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000044
Michael J. Spencere1630da2010-09-17 06:33:20 +000045 <p>There are many different projects that compose LLVM. The first is the LLVM
46 suite. This contains all of the tools, libraries, and header files needed to
Jim Grosbachc48d4dc2012-01-25 22:00:23 +000047 use LLVM. It contains an assembler, disassembler,
Michael J. Spencere1630da2010-09-17 06:33:20 +000048 bitcode analyzer and bitcode optimizer. It also contains a test suite that can
49 be used to test the LLVM tools.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000050
Michael J. Spencere1630da2010-09-17 06:33:20 +000051 <p>Another useful project on Windows is
52 <a href="http://clang.llvm.org/">clang</a>. Clang is a C family
Michael J. Spenceraf3874d2010-09-18 08:32:32 +000053 ([Objective]C/C++) compiler. Clang mostly works on Windows, but does not
Michael J. Spencere1630da2010-09-17 06:33:20 +000054 currently understand all of the Microsoft extensions to C and C++. Because of
55 this, clang cannot parse the C++ standard library included with Visual Studio,
56 nor parts of the Windows Platform SDK. However, most standard C programs do
57 compile. Clang can be used to emit bitcode, directly emit object files or
58 even linked executables using Visual Studio's <tt>link.exe</tt></p>
59
Michael J. Spenceraf3874d2010-09-18 08:32:32 +000060 <p>The large LLVM test suite cannot be run on the Visual Studio port at this
Michael J. Spencere1630da2010-09-17 06:33:20 +000061 time.</p>
62
63 <p>Most of the tools build and work. <tt>bugpoint</tt> does build, but does
64 not work.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000065
66 <p>Additional information about the LLVM directory structure and tool chain
67 can be found on the main <a href="GettingStarted.html">Getting Started</a>
Nick Lewycky28ea4f62008-12-08 00:45:02 +000068 page.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000069
70</div>
71
72<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000073<h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000074 <a name="requirements"><b>Requirements</b></a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000075</h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000076<!-- *********************************************************************** -->
77
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000078<div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000079
80 <p>Before you begin to use the LLVM system, review the requirements given
81 below. This may save you some trouble by knowing ahead of time what hardware
82 and software you will need.</p>
83
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000084<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000085<h3>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000086 <a name="hardware"><b>Hardware</b></a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000087</h3>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000088
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000089<div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000090
Chandler Carruth2929de42011-11-16 19:52:13 +000091 <p>Any system that can adequately run Visual Studio 2008 is fine. The LLVM
92 source tree and object files, libraries and executables will consume
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000093 approximately 3GB.</p>
94
95</div>
96
97<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000098<h3><a name="software"><b>Software</b></a></h3>
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000099<div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000100
Chandler Carruth2929de42011-11-16 19:52:13 +0000101 <p>You will need Visual Studio 2008 or higher. Earlier versions of Visual
102 Studio have bugs, are not completely compatible, or do not support the C++
103 standard well enough.</p>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000104
Nick Lewycky28ea4f62008-12-08 00:45:02 +0000105 <p>You will also need the <a href="http://www.cmake.org/">CMake</a> build
106 system since it generates the project files you will use to build with.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000107
Michael J. Spencere1630da2010-09-17 06:33:20 +0000108 <p>If you would like to run the LLVM tests you will need
109 <a href="http://www.python.org/">Python</a>. Versions 2.4-2.7 are known to
NAKAMURA Takumif287f012011-02-09 04:19:28 +0000110 work. You will need <a href="http://gnuwin32.sourceforge.net/">"GnuWin32"</a>
111 tools, too.</p>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000112
113 <p>Do not install the LLVM directory tree into a path containing spaces (e.g.
Chris Lattnerc2bb1232007-11-14 07:04:44 +0000114 C:\Documents and Settings\...) as the configure step will fail.</p>
115
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000116</div>
117
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000118</div>
119
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000120<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000121<h2>
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000122 <a name="quickstart"><b>Getting Started</b></a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000123</h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000124<!-- *********************************************************************** -->
125
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000126<div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000127
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000128<p>Here's the short story for getting up and running quickly with LLVM:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000129
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000130<ol>
131 <li>Read the documentation.</li>
132 <li>Seriously, read the documentation.</li>
133 <li>Remember that you were warned twice about reading the documentation.</li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000134
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000135 <li>Get the Source Code
136 <ul>
137 <li>With the distributed files:
138 <ol>
139 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
140 <li><tt>gunzip --stdout llvm-<i>version</i>.tar.gz | tar -xvf -</tt>
141 <i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or use WinZip</i>
142 <li><tt>cd llvm</tt></li>
143 </ol></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000144
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000145 <li>With anonymous Subversion access:
146 <ol>
147 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt></li>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000148 <li><tt>svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</tt></li>
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000149 <li><tt>cd llvm</tt></li>
150 </ol></li>
151 </ul></li>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000152
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000153 <li> Use <a href="http://www.cmake.org/">CMake</a> to generate up-to-date
154 project files:
155 <ul>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000156 <li>Once CMake is installed then the simplest way is to just start the
157 CMake GUI, select the directory where you have LLVM extracted to, and the
158 default options should all be fine. One option you may really want to
159 change, regardless of anything else, might be the CMAKE_INSTALL_PREFIX
160 setting to select a directory to INSTALL to once compiling is complete,
161 although installation is not mandatory for using LLVM. Another important
162 option is LLVM_TARGETS_TO_BUILD, which controls the LLVM target
163 architectures that are included on the build.
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000164 <li>See the <a href="CMake.html">LLVM CMake guide</a> for
165 detailed information about how to configure the LLVM
166 build.</li>
167 </ul>
168 </li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000169
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000170 <li>Start Visual Studio
171 <ul>
172 <li>In the directory you created the project files will have
173 an <tt>llvm.sln</tt> file, just double-click on that to open
174 Visual Studio.</li>
175 </ul></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000176
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000177 <li>Build the LLVM Suite:
178 <ul>
179 <li>The projects may still be built individually, but
180 to build them all do not just select all of them in batch build (as some
181 are meant as configuration projects), but rather select and build just
182 the ALL_BUILD project to build everything, or the INSTALL project, which
183 first builds the ALL_BUILD project, then installs the LLVM headers, libs,
184 and other useful things to the directory set by the CMAKE_INSTALL_PREFIX
185 setting when you first configured CMake.</li>
186 <li>The Fibonacci project is a sample program that uses the JIT.
187 Modify the project's debugging properties to provide a numeric
188 command line argument or run it from the command line. The
189 program will print the corresponding fibonacci value.</li>
190 </ul></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000191
NAKAMURA Takumif287f012011-02-09 04:19:28 +0000192 <li>Test LLVM on Visual Studio:
193 <ul>
194 <li>If %PATH% does not contain GnuWin32, you may specify LLVM_LIT_TOOLS_DIR
195 on CMake for the path to GnuWin32.</li>
Oscar Fuentesbbe9d342011-04-10 01:41:55 +0000196 <li>You can run LLVM tests by merely building the project
197 "check". The test results will be shown in the VS output
198 window.</li>
NAKAMURA Takumif287f012011-02-09 04:19:28 +0000199 </ul>
200 </li>
201
202 <!-- FIXME: Is it up-to-date? -->
Michael J. Spencere1630da2010-09-17 06:33:20 +0000203 <li>Test LLVM:
204 <ul>
205 <li>The LLVM tests can be run by <tt>cd</tt>ing to the llvm source directory
206 and running:
207
208<div class="doc_code">
209<pre>
210% llvm-lit test
211</pre>
212</div>
213
214 <p>Note that quite a few of these test will fail.</p>
215 </li>
216
NAKAMURA Takumi4d6deb02011-04-09 09:51:57 +0000217 <li>A specific test or test directory can be run with:
Michael J. Spencere1630da2010-09-17 06:33:20 +0000218
219<div class="doc_code">
220<pre>
221% llvm-lit test/path/to/test
222</pre>
223</div>
NAKAMURA Takumi4d6deb02011-04-09 09:51:57 +0000224 </li>
225 </ul>
Oscar Fuentes96b5f712010-09-17 02:17:13 +0000226</ol>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000227
228</div>
229
230<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000231<h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000232 <a name="tutorial">An Example Using the LLVM Tool Chain</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000233</h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000234<!-- *********************************************************************** -->
235
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000236<div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000237
238<ol>
Bill Wendling03c993a2007-09-22 09:39:19 +0000239 <li><p>First, create a simple C file, name it 'hello.c':</p>
240
241<div class="doc_code">
242<pre>
243#include &lt;stdio.h&gt;
244int main() {
245 printf("hello world\n");
246 return 0;
247}
248</pre></div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000249
Gabor Greif04367bf2007-07-06 22:07:22 +0000250 <li><p>Next, compile the C file into a LLVM bitcode file:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000251
Bill Wendling03c993a2007-09-22 09:39:19 +0000252<div class="doc_code">
253<pre>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000254% clang -c hello.c -emit-llvm -o hello.bc
Bill Wendling03c993a2007-09-22 09:39:19 +0000255</pre>
256</div>
257
258 <p>This will create the result file <tt>hello.bc</tt> which is the LLVM
259 bitcode that corresponds the the compiled program and the library
260 facilities that it required. You can execute this file directly using
261 <tt>lli</tt> tool, compile it to native assembly with the <tt>llc</tt>,
262 optimize or analyze it further with the <tt>opt</tt> tool, etc.</p>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000263
264 <p>Alternatively you can directly output an executable with clang with:
265 </p>
266
267<div class="doc_code">
268<pre>
269% clang hello.c -o hello.exe
270</pre>
271</div>
272
273 <p>The <tt>-o hello.exe</tt> is required because clang currently outputs
274 <tt>a.out</tt> when neither <tt>-o</tt> nor <tt>-c</tt> are given.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000275
Jeff Cohena0887342005-10-30 21:00:24 +0000276 <li><p>Run the program using the just-in-time compiler:</p>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000277
Bill Wendling03c993a2007-09-22 09:39:19 +0000278<div class="doc_code">
279<pre>
280% lli hello.bc
281</pre>
282</div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000283
284 <li><p>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
285 code:</p>
286
Bill Wendling03c993a2007-09-22 09:39:19 +0000287<div class="doc_code">
288<pre>
289% llvm-dis &lt; hello.bc | more
290</pre>
291</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000292
Michael J. Spencere1630da2010-09-17 06:33:20 +0000293 <li><p>Compile the program to object code using the LLC code generator:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000294
Bill Wendling03c993a2007-09-22 09:39:19 +0000295<div class="doc_code">
296<pre>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000297% llc -filetype=obj hello.bc
Bill Wendling03c993a2007-09-22 09:39:19 +0000298</pre>
299</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000300
Michael J. Spencere1630da2010-09-17 06:33:20 +0000301 <li><p>Link to binary using Microsoft link:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000302
Bill Wendling03c993a2007-09-22 09:39:19 +0000303<div class="doc_code">
304<pre>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000305% link hello.obj -defaultlib:libcmt
Bill Wendling03c993a2007-09-22 09:39:19 +0000306</pre>
307</div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000308
309 <li><p>Execute the native code program:</p>
310
Bill Wendling03c993a2007-09-22 09:39:19 +0000311<div class="doc_code">
312<pre>
Michael J. Spencere1630da2010-09-17 06:33:20 +0000313% hello.exe
Bill Wendling03c993a2007-09-22 09:39:19 +0000314</pre>
315</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000316</ol>
317
318</div>
319
320<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000321<h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000322 <a name="problems">Common Problems</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000323</h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000324<!-- *********************************************************************** -->
325
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000326<div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000327
328<p>If you are having problems building or using LLVM, or if you have any other
329general questions about LLVM, please consult the <a href="FAQ.html">Frequently
330Asked Questions</a> page.</p>
331
332</div>
333
334<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000335<h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000336 <a name="links">Links</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000337</h2>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000338<!-- *********************************************************************** -->
339
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000340<div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000341
342<p>This document is just an <b>introduction</b> to how to use LLVM to do
343some simple things... there are many more interesting and complicated things
344that you can do that aren't documented here (but we'll gladly accept a patch
345if you want to write something up!). For more information about LLVM, check
346out:</p>
347
348<ul>
Reid Spencer05fe4b02006-03-14 05:39:39 +0000349 <li><a href="http://llvm.org/">LLVM homepage</a></li>
350 <li><a href="http://llvm.org/doxygen/">LLVM doxygen tree</a></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000351</ul>
352
353</div>
354
355<!-- *********************************************************************** -->
356
357<hr>
358<address>
359 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000360 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000361 <a href="http://validator.w3.org/check/referer"><img
Misha Brukmanf00ddb02008-12-11 18:23:24 +0000362 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000363
NAKAMURA Takumib9a33632011-04-09 02:13:37 +0000364 <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000365 Last modified: $Date$
366</address>
367</body>
368</html>