Remove the link to Projects.html. It is useless for people working on
[oota-llvm.git] / docs / GettingStartedVS.html
1 <!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="#requirements">Requirements</a>
18     <ol>
19       <li><a href="#hardware">Hardware</a>
20       <li><a href="#software">Software</a>
21     </ol></li>
22   <li><a href="#quickstart">Getting Started</a>
23   <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">
29   <p>Written by:
30     <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a>
31   </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
43   <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>
46
47   <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>
52
53   <p>Another useful project on Windows is
54   <a href="http://clang.llvm.org/">clang</a>. Clang is a C family
55   ([Objective]C/C++) compiler. Clang mostly works on Windows, but does not
56   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
62   <p>The large LLVM test suite cannot be run on the Visual Studio port at this
63   time.</p>
64
65   <p>Most of the tools build and work.  <tt>bugpoint</tt> does build, but does
66   not work.</p>
67
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>
70   page.</p>
71
72 </div>
73
74 <!-- *********************************************************************** -->
75 <div class="doc_section">
76   <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
95   <p>Any system that can adequately run Visual Studio .NET 2005 SP1 is fine.
96   The LLVM source tree and object files, libraries and executables will consume
97   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
105   <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
107   compatible.  Earlier versions of Visual Studio do not support the C++ standard
108   well enough and will not work.</p>
109
110   <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>
112
113   <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. You will need <a href="http://gnuwin32.sourceforge.net/">"GnuWin32"</a>
116   tools, too.</p>
117
118   <p>Do not install the LLVM directory tree into a path containing spaces (e.g.
119   C:\Documents and Settings\...) as the configure step will fail.</p>
120
121 </div>
122
123 <!-- *********************************************************************** -->
124 <div class="doc_section">
125   <a name="quickstart"><b>Getting Started</b></a>
126 </div>
127 <!-- *********************************************************************** -->
128
129 <div class="doc_text">
130
131 <p>Here's the short story for getting up and running quickly with LLVM:</p>
132
133 <ol>
134   <li>Read the documentation.</li>
135   <li>Seriously, read the documentation.</li>
136   <li>Remember that you were warned twice about reading the documentation.</li>
137
138   <li>Get the Source Code
139   <ul>
140     <li>With the distributed files:
141     <ol>
142       <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
143       <li><tt>gunzip --stdout llvm-<i>version</i>.tar.gz | tar -xvf -</tt>
144       <i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or use WinZip</i>
145       <li><tt>cd llvm</tt></li>
146     </ol></li>
147
148     <li>With anonymous Subversion access:
149     <ol>
150       <li><tt>cd <i>where-you-want-llvm-to-live</i></tt></li>
151       <li><tt>svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</tt></li>
152       <li><tt>cd llvm</tt></li>
153     </ol></li>
154   </ul></li>
155
156   <li> Use <a href="http://www.cmake.org/">CMake</a> to generate up-to-date
157     project files:
158     <ul>
159       <li>Once CMake is installed then the simplest way is to just start the
160         CMake GUI, select the directory where you have LLVM extracted to, and the
161         default options should all be fine.  One option you may really want to
162         change, regardless of anything else, might be the CMAKE_INSTALL_PREFIX
163         setting to select a directory to INSTALL to once compiling is complete,
164         although installation is not mandatory for using LLVM.  Another important
165         option is LLVM_TARGETS_TO_BUILD, which controls the LLVM target
166         architectures that are included on the build.
167       <li>See the <a href="CMake.html">LLVM CMake guide</a> for
168         detailed information about how to configure the LLVM
169         build.</li>
170     </ul>
171   </li>
172
173   <li>Start Visual Studio
174   <ul>
175     <li>In the directory you created the project files will have
176     an <tt>llvm.sln</tt> file, just double-click on that to open
177     Visual Studio.</li>
178   </ul></li>
179
180   <li>Build the LLVM Suite:
181   <ul>
182     <li>The projects may still be built individually, but
183     to build them all do not just select all of them in batch build (as some
184     are meant as configuration projects), but rather select and build just
185     the ALL_BUILD project to build everything, or the INSTALL project, which
186     first builds the ALL_BUILD project, then installs the LLVM headers, libs,
187     and other useful things to the directory set by the CMAKE_INSTALL_PREFIX
188     setting when you first configured CMake.</li>
189     <li>The Fibonacci project is a sample program that uses the JIT.
190     Modify the project's debugging properties to provide a numeric
191     command line argument or run it from the command line.  The
192     program will print the corresponding fibonacci value.</li>
193   </ul></li>
194
195   <li>Test LLVM on Visual Studio:
196   <ul>
197     <li>If %PATH% does not contain GnuWin32, you may specify LLVM_LIT_TOOLS_DIR
198     on CMake for the path to GnuWin32.</li>
199     <li>You can run LLVM tests to build the project "check".</li>
200   </ul>
201   </li>
202
203   <!-- FIXME: Is it up-to-date? -->
204   <li>Test LLVM:
205   <ul>
206     <li>The LLVM tests can be run by <tt>cd</tt>ing to the llvm source directory
207         and running:
208
209 <div class="doc_code">
210 <pre>
211 % llvm-lit test
212 </pre>
213 </div>
214
215     <p>Note that quite a few of these test will fail.</p>
216     </li>
217
218     <li>A specific test or test directory can be run with:</li>
219
220 <div class="doc_code">
221 <pre>
222 % llvm-lit test/path/to/test
223 </pre>
224 </div>
225
226 </ol>
227
228 </div>
229
230 <!-- *********************************************************************** -->
231 <div class="doc_section">
232   <a name="tutorial">An Example Using the LLVM Tool Chain</a>
233 </div>
234 <!-- *********************************************************************** -->
235
236 <div class="doc_text">
237
238 <ol>
239   <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;
244 int main() {
245   printf("hello world\n");
246   return 0;
247 }
248 </pre></div></li>
249
250   <li><p>Next, compile the C file into a LLVM bitcode file:</p>
251
252 <div class="doc_code">
253 <pre>
254 % clang -c hello.c -emit-llvm -o hello.bc
255 </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>
263
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>
275
276   <li><p>Run the program using the just-in-time compiler:</p>
277
278 <div class="doc_code">
279 <pre>
280 % lli hello.bc
281 </pre>
282 </div>
283
284   <li><p>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
285       code:</p>
286
287 <div class="doc_code">
288 <pre>
289 % llvm-dis &lt; hello.bc | more
290 </pre>
291 </div></li>
292
293   <li><p>Compile the program to object code using the LLC code generator:</p>
294
295 <div class="doc_code">
296 <pre>
297 % llc -filetype=obj hello.bc
298 </pre>
299 </div></li>
300
301   <li><p>Link to binary using Microsoft link:</p>
302
303 <div class="doc_code">
304 <pre>
305 % link hello.obj -defaultlib:libcmt
306 </pre>
307 </div>
308
309   <li><p>Execute the native code program:</p>
310
311 <div class="doc_code">
312 <pre>
313 % hello.exe
314 </pre>
315 </div></li>
316 </ol>
317
318 </div>
319
320 <!-- *********************************************************************** -->
321 <div class="doc_section">
322   <a name="problems">Common Problems</a>
323 </div>
324 <!-- *********************************************************************** -->
325
326 <div class="doc_text">
327
328 <p>If you are having problems building or using LLVM, or if you have any other
329 general questions about LLVM, please consult the <a href="FAQ.html">Frequently
330 Asked Questions</a> page.</p>
331
332 </div>
333
334 <!-- *********************************************************************** -->
335 <div class="doc_section">
336   <a name="links">Links</a>
337 </div>
338 <!-- *********************************************************************** -->
339
340 <div class="doc_text">
341
342 <p>This document is just an <b>introduction</b> to how to use LLVM to do
343 some simple things... there are many more interesting and complicated things
344 that you can do that aren't documented here (but we'll gladly accept a patch
345 if you want to write something up!).  For more information about LLVM, check
346 out:</p>
347
348 <ul>
349   <li><a href="http://llvm.org/">LLVM homepage</a></li>
350   <li><a href="http://llvm.org/doxygen/">LLVM doxygen tree</a></li>
351 </ul>
352
353 </div>
354
355 <!-- *********************************************************************** -->
356
357 <hr>
358 <address>
359   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
360   src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
361   <a href="http://validator.w3.org/check/referer"><img
362   src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
363
364   <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a><br>
365   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
366   Last modified: $Date$
367 </address>
368 </body>
369 </html>