blob: 5a86199f7e4d6de8f63df90b1132c8ae7d148b4f [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>
17 <li><a href="#quickstart">Getting Started Quickly (A Summary)</a>
18 <li><a href="#requirements">Requirements</a>
19 <ol>
20 <li><a href="#hardware">Hardware</a>
21 <li><a href="#software">Software</a>
22 </ol></li>
23
24 <li><a href="#starting">Getting Started with LLVM</a>
25 <ol>
26 <li><a href="#terminology">Terminology and Notation</a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000027 <li><a href="#objfiles">The Location of LLVM Object Files</a>
28 </ol></li>
29
30 <li><a href="#tutorial">An Example Using the LLVM Tool Chain</a>
31 <li><a href="#problems">Common Problems</a>
32 <li><a href="#links">Links</a>
33</ul>
34
35<div class="doc_author">
36 <p>Written by:
Jeff Cohenb9a47d12005-02-01 15:59:28 +000037 <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000038 </p>
39</div>
40
41
42<!-- *********************************************************************** -->
43<div class="doc_section">
44 <a name="overview"><b>Overview</b></a>
45</div>
46<!-- *********************************************************************** -->
47
48<div class="doc_text">
49
50 <p>The Visual Studio port at this time is experimental. It is suitable for
51 use only if you are writing your own compiler front end or otherwise have a
52 need to dynamically generate machine code. The JIT and interpreter are
Jeff Cohenca0a9092005-03-08 03:56:50 +000053 functional, but it is currently not possible to generate assembly code which
54 is then assembled into an executable. You can indirectly create executables
55 by using the C back end.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000056
Jeff Cohenb9a47d12005-02-01 15:59:28 +000057 <p>To emphasize, there is no C/C++ front end currently available.
58 <tt>llvm-gcc</tt> is based on GCC, which cannot be bootstrapped using VC++.
59 Eventually there should be a <tt>llvm-gcc</tt> based on Cygwin or MinGW that
Gabor Greif04367bf2007-07-06 22:07:22 +000060 is usable. There is also the option of generating bitcode files on Unix and
Jeff Cohenb9a47d12005-02-01 15:59:28 +000061 copying them over to Windows. But be aware the odds of linking C++ code
62 compiled with <tt>llvm-gcc</tt> with code compiled with VC++ is essentially
63 zero.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000064
65 <p>The LLVM test suite cannot be run on the Visual Studio port at this
66 time.</p>
67
Nick Lewycky28ea4f62008-12-08 00:45:02 +000068 <p>Most of the tools build and work. <tt>bugpoint</tt> does build, but does
69 not work. The other tools 'should' work, but have not been fully tested.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000070
71 <p>Additional information about the LLVM directory structure and tool chain
72 can be found on the main <a href="GettingStarted.html">Getting Started</a>
Nick Lewycky28ea4f62008-12-08 00:45:02 +000073 page.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000074
75</div>
76
77<!-- *********************************************************************** -->
78<div class="doc_section">
79 <a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a>
80</div>
81<!-- *********************************************************************** -->
82
83<div class="doc_text">
84
85<p>Here's the short story for getting up and running quickly with LLVM:</p>
86
87<ol>
88 <li>Read the documentation.</li>
Bill Wendling03c993a2007-09-22 09:39:19 +000089 <li>Seriously, read the documentation.</li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000090 <li>Remember that you were warned twice about reading the documentation.</li>
91
92 <li>Get the Source Code
93 <ul>
94 <li>With the distributed files:
95 <ol>
96 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
97 <li><tt>gunzip --stdout llvm-<i>version</i>.tar.gz | tar -xvf -</tt>
Jeff Cohenb9a47d12005-02-01 15:59:28 +000098 <i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or use WinZip</i>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000099 <li><tt>cd llvm</tt></li>
100 </ol></li>
101
Reid Spencer669ed452007-07-09 08:04:31 +0000102 <li>With anonymous Subversion access:
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000103 <ol>
104 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt></li>
Reid Spencer669ed452007-07-09 08:04:31 +0000105 <li><tt>svn co http://llvm.org/svn/llvm-project/llvm-top/trunk llvm-top
106 </tt></li>
107 <li><tt>make checkout MODULE=llvm</tt>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000108 <li><tt>cd llvm</tt></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000109 </ol></li>
110 </ul></li>
Nick Lewycky28ea4f62008-12-08 00:45:02 +0000111
112 <li> Use <a href="http://www.cmake.org/">CMake</a> to generate up-to-date
113 project files:
114 <ul><li>This step is currently optional as LLVM does still come with a
115 normal Visual Studio solution file, but it is not always kept up-to-date
116 and will soon be deprecated in favor of the multi-platform generator
117 CMake.</li>
118 <li>If CMake is installed then the most simple way is to just start the
119 CMake GUI, select the directory where you have LLVM extracted to, and
120 the default options should all be fine. The one option you may really
121 want to change, regardless of anything else, might be the
122 CMAKE_INSTALL_PREFIX setting to select a directory to INSTALL to once
123 compiling is complete.</li>
124 <li>If you use CMake to generate the Visual Studio solution and project
125 files, then the Solution will have a few extra options compared to the
126 current included one. The projects may still be built individually, but
127 to build them all do not just select all of them in batch build (as some
128 are meant as configuration projects), but rather select and build just
129 the ALL_BUILD project to build everything, or the INSTALL project, which
130 first builds the ALL_BUILD project, then installs the LLVM headers, libs,
131 and other useful things to the directory set by the CMAKE_INSTALL_PREFIX
132 setting when you first configured CMake.</li>
133 </ul>
134 </li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000135
136 <li>Start Visual Studio
Nick Lewycky28ea4f62008-12-08 00:45:02 +0000137 <ul>
138 <li>If you did not use CMake, then simply double click on the solution
139 file <tt>llvm/win32/llvm.sln</tt>.</li>
140 <li>If you used CMake, then the directory you created the project files,
141 the root directory will have an <tt>llvm.sln</tt> file, just
142 double-click on that to open Visual Studio.</li>
Benjamin Kramere15192b2009-08-05 15:42:44 +0000143 </ul></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000144
145 <li>Build the LLVM Suite:
Benjamin Kramere15192b2009-08-05 15:42:44 +0000146 <ul>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000147 <li>Simply build the solution.</li>
148 <li>The Fibonacci project is a sample program that uses the JIT. Modify
149 the project's debugging properties to provide a numeric command line
150 argument. The program will print the corresponding fibonacci value.</li>
Benjamin Kramere15192b2009-08-05 15:42:44 +0000151 </ul></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000152
153</ol>
154
Reid Spencer669ed452007-07-09 08:04:31 +0000155<p>It is strongly encouraged that you get the latest version from Subversion as
156changes are continually making the VS support better.</p>
Jeff Cohenb9a47d12005-02-01 15:59:28 +0000157
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000158</div>
159
160<!-- *********************************************************************** -->
161<div class="doc_section">
162 <a name="requirements"><b>Requirements</b></a>
163</div>
164<!-- *********************************************************************** -->
165
166<div class="doc_text">
167
168 <p>Before you begin to use the LLVM system, review the requirements given
169 below. This may save you some trouble by knowing ahead of time what hardware
170 and software you will need.</p>
171
172</div>
173
174<!-- ======================================================================= -->
175<div class="doc_subsection">
176 <a name="hardware"><b>Hardware</b></a>
177</div>
178
179<div class="doc_text">
180
Nick Lewycky28ea4f62008-12-08 00:45:02 +0000181 <p>Any system that can adequately run Visual Studio .NET 2005 SP1 is fine.
182 The LLVM source tree and object files, libraries and executables will consume
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000183 approximately 3GB.</p>
184
185</div>
186
187<!-- ======================================================================= -->
188<div class="doc_subsection"><a name="software"><b>Software</b></a></div>
189<div class="doc_text">
190
Nick Lewycky28ea4f62008-12-08 00:45:02 +0000191 <p>You will need Visual Studio .NET 2005 SP1 or higher. The VS2005 SP1
192 beta and the normal VS2005 still have bugs that are not completely
193 compatible. VS2003 would work except (at last check) it has a bug with
194 friend classes that you can work-around with some minor code rewriting
195 (and please submit a patch if you do). Earlier versions of Visual Studio
196 do not support the C++ standard well enough and will not work.</p>
197
198 <p>You will also need the <a href="http://www.cmake.org/">CMake</a> build
199 system since it generates the project files you will use to build with.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000200
Chris Lattnerc2bb1232007-11-14 07:04:44 +0000201 <p>
202 Do not install the LLVM directory tree into a path containing spaces (e.g.
203 C:\Documents and Settings\...) as the configure step will fail.</p>
204
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000205</div>
206
207<!-- *********************************************************************** -->
208<div class="doc_section">
209 <a name="starting"><b>Getting Started with LLVM</b></a>
210</div>
211<!-- *********************************************************************** -->
212
213<div class="doc_text">
214
215<p>The remainder of this guide is meant to get you up and running with
216LLVM using Visual Studio and to give you some basic information about the LLVM
217environment.</p>
218
219</div>
220
221<!-- ======================================================================= -->
222<div class="doc_subsection">
223 <a name="terminology">Terminology and Notation</a>
224</div>
225
226<div class="doc_text">
227
228<p>Throughout this manual, the following names are used to denote paths
229specific to the local system and working environment. <i>These are not
230environment variables you need to set but just strings used in the rest
231of this document below</i>. In any of the examples below, simply replace
232each of these names with the appropriate pathname on your local system.
233All these paths are absolute:</p>
234
235<dl>
Bill Wendling03c993a2007-09-22 09:39:19 +0000236 <dt>SRC_ROOT</dt>
237 <dd><p>This is the top level directory of the LLVM source tree.</p></dd>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000238
Bill Wendling03c993a2007-09-22 09:39:19 +0000239 <dt>OBJ_ROOT</dt>
240 <dd><p>This is the top level directory of the LLVM object tree (i.e. the
241 tree where object files and compiled programs will be placed. It is
242 fixed at SRC_ROOT/win32).</p></dd>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000243</dl>
244
245</div>
246
247<!-- ======================================================================= -->
248<div class="doc_subsection">
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000249 <a name="objfiles">The Location of LLVM Object Files</a>
250</div>
251
252<div class="doc_text">
253
254 <p>The object files are placed under <tt>OBJ_ROOT/Debug</tt> for debug builds
255 and <tt>OBJ_ROOT/Release</tt> for release (optimized) builds. These include
Bill Wendling03c993a2007-09-22 09:39:19 +0000256 both executables and libararies that your application can link against.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000257
258 <p>The files that <tt>configure</tt> would create when building on Unix are
259 created by the <tt>Configure</tt> project and placed in
260 <tt>OBJ_ROOT/llvm</tt>. You application must have OBJ_ROOT in its include
Bill Wendling03c993a2007-09-22 09:39:19 +0000261 search path just before <tt>SRC_ROOT/include</tt>.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000262
263</div>
264
265<!-- *********************************************************************** -->
266<div class="doc_section">
267 <a name="tutorial">An Example Using the LLVM Tool Chain</a>
268</div>
269<!-- *********************************************************************** -->
270
271<div class="doc_text">
272
273<ol>
Bill Wendling03c993a2007-09-22 09:39:19 +0000274 <li><p>First, create a simple C file, name it 'hello.c':</p>
275
276<div class="doc_code">
277<pre>
278#include &lt;stdio.h&gt;
279int main() {
280 printf("hello world\n");
281 return 0;
282}
283</pre></div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000284
Gabor Greif04367bf2007-07-06 22:07:22 +0000285 <li><p>Next, compile the C file into a LLVM bitcode file:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000286
Bill Wendling03c993a2007-09-22 09:39:19 +0000287<div class="doc_code">
288<pre>
289% llvm-gcc -c hello.c -emit-llvm -o hello.bc
290</pre>
291</div>
292
293 <p>This will create the result file <tt>hello.bc</tt> which is the LLVM
294 bitcode that corresponds the the compiled program and the library
295 facilities that it required. You can execute this file directly using
296 <tt>lli</tt> tool, compile it to native assembly with the <tt>llc</tt>,
297 optimize or analyze it further with the <tt>opt</tt> tool, etc.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000298
299 <p><b>Note: while you cannot do this step on Windows, you can do it on a
Bill Wendling03c993a2007-09-22 09:39:19 +0000300 Unix system and transfer <tt>hello.bc</tt> to Windows. Important:
301 transfer as a binary file!</b></p></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000302
Jeff Cohena0887342005-10-30 21:00:24 +0000303 <li><p>Run the program using the just-in-time compiler:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000304
Bill Wendling03c993a2007-09-22 09:39:19 +0000305<div class="doc_code">
306<pre>
307% lli hello.bc
308</pre>
309</div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000310
Jeff Cohen3c8dfcd2007-03-28 20:27:51 +0000311 <p>Note: this will only work for trivial C programs. Non-trivial programs
Bill Wendling03c993a2007-09-22 09:39:19 +0000312 (and any C++ program) will have dependencies on the GCC runtime that
313 won't be satisfied by the Microsoft runtime libraries.</p></li>
Jeff Cohen3c8dfcd2007-03-28 20:27:51 +0000314
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000315 <li><p>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
316 code:</p>
317
Bill Wendling03c993a2007-09-22 09:39:19 +0000318<div class="doc_code">
319<pre>
320% llvm-dis &lt; hello.bc | more
321</pre>
322</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000323
Jeff Cohena0887342005-10-30 21:00:24 +0000324 <li><p>Compile the program to C using the LLC code generator:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000325
Bill Wendling03c993a2007-09-22 09:39:19 +0000326<div class="doc_code">
327<pre>
328% llc -march=c hello.bc
329</pre>
330</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000331
Jeff Cohena0887342005-10-30 21:00:24 +0000332 <li><p>Compile to binary using Microsoft C:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000333
Bill Wendling03c993a2007-09-22 09:39:19 +0000334<div class="doc_code">
335<pre>
336% cl hello.cbe.c
337</pre>
338</div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000339
Bill Wendlingbc14dd32009-03-28 10:24:15 +0000340 <p>Note: this will only work for trivial C programs. Non-trivial programs
341 (and any C++ program) will have dependencies on the GCC runtime that won't
342 be satisfied by the Microsoft runtime libraries.</p></li>
Jeff Cohen3c8dfcd2007-03-28 20:27:51 +0000343
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000344 <li><p>Execute the native code program:</p>
345
Bill Wendling03c993a2007-09-22 09:39:19 +0000346<div class="doc_code">
347<pre>
348% hello.cbe.exe
349</pre>
350</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000351</ol>
352
353</div>
354
355<!-- *********************************************************************** -->
356<div class="doc_section">
357 <a name="problems">Common Problems</a>
358</div>
359<!-- *********************************************************************** -->
360
361<div class="doc_text">
362
Bill Wendlingbc14dd32009-03-28 10:24:15 +0000363 <ul>
364 <li>In Visual C++, if you are linking with the x86 target statically, the
365 linker will remove the x86 target library from your generated executable or
366 shared library because there are no references to it. You can force the
367 linker to include these references by using
368 <tt>"/INCLUDE:_X86TargetMachineModule"</tt> when linking. In the Visual
369 Studio IDE, this can be added in
370<tt>Project&nbsp;Properties->Linker->Input->Force&nbsp;Symbol&nbsp;References</tt>.
371 </li>
372 </ul>
373
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000374<p>If you are having problems building or using LLVM, or if you have any other
375general questions about LLVM, please consult the <a href="FAQ.html">Frequently
376Asked Questions</a> page.</p>
377
378</div>
379
380<!-- *********************************************************************** -->
381<div class="doc_section">
382 <a name="links">Links</a>
383</div>
384<!-- *********************************************************************** -->
385
386<div class="doc_text">
387
388<p>This document is just an <b>introduction</b> to how to use LLVM to do
389some simple things... there are many more interesting and complicated things
390that you can do that aren't documented here (but we'll gladly accept a patch
391if you want to write something up!). For more information about LLVM, check
392out:</p>
393
394<ul>
Reid Spencer05fe4b02006-03-14 05:39:39 +0000395 <li><a href="http://llvm.org/">LLVM homepage</a></li>
396 <li><a href="http://llvm.org/doxygen/">LLVM doxygen tree</a></li>
397 <li><a href="http://llvm.org/docs/Projects.html">Starting a Project
Bill Wendling03c993a2007-09-22 09:39:19 +0000398 that Uses LLVM</a></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000399</ul>
400
401</div>
402
403<!-- *********************************************************************** -->
404
405<hr>
406<address>
407 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000408 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000409 <a href="http://validator.w3.org/check/referer"><img
Misha Brukmanf00ddb02008-12-11 18:23:24 +0000410 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000411
Jeff Cohenb9a47d12005-02-01 15:59:28 +0000412 <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +0000413 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000414 Last modified: $Date$
415</address>
416</body>
417</html>