blob: aa980d20d246b024d5e41b6a55ebe3ecb5d0e057 [file] [log] [blame]
Michael J. Spencerd93399a2012-06-21 23:27:09 +00001==================================================================
2Getting Started with the LLVM System using Microsoft Visual Studio
3==================================================================
4
5.. contents::
6 :local:
7
8
9Overview
10========
11Welcome to LLVM on Windows! This document only covers LLVM on Windows using
12Visual Studio, not mingw or cygwin. In order to get started, you first need to
13know some basic information.
14
15There are many different projects that compose LLVM. The first is the LLVM
16suite. This contains all of the tools, libraries, and header files needed to
17use LLVM. It contains an assembler, disassembler,
18bitcode analyzer and bitcode optimizer. It also contains a test suite that can
19be used to test the LLVM tools.
20
21Another useful project on Windows is `Clang <http://clang.llvm.org/>`_.
22Clang is a C family ([Objective]C/C++) compiler. Clang mostly works on
23Windows, but does not currently understand all of the Microsoft extensions
24to C and C++. Because of this, clang cannot parse the C++ standard library
25included with Visual Studio, nor parts of the Windows Platform SDK. However,
26most standard C programs do compile. Clang can be used to emit bitcode,
27directly emit object files or even linked executables using Visual Studio's
28``link.exe``.
29
30The large LLVM test suite cannot be run on the Visual Studio port at this
31time.
32
33Most of the tools build and work. ``bugpoint`` does build, but does
34not work.
35
36Additional information about the LLVM directory structure and tool chain
Sean Silva1703e702014-04-08 21:06:22 +000037can be found on the main :doc:`GettingStarted` page.
Michael J. Spencerd93399a2012-06-21 23:27:09 +000038
39
40Requirements
41============
42Before you begin to use the LLVM system, review the requirements given
43below. This may save you some trouble by knowing ahead of time what hardware
44and software you will need.
45
46Hardware
47--------
Aaron Ballman1e9d9b22014-01-23 20:46:44 +000048Any system that can adequately run Visual Studio 2012 is fine. The LLVM
Michael J. Spencerd93399a2012-06-21 23:27:09 +000049source tree and object files, libraries and executables will consume
50approximately 3GB.
51
52Software
53--------
Aaron Ballman1e9d9b22014-01-23 20:46:44 +000054You will need Visual Studio 2012 or higher.
Michael J. Spencerd93399a2012-06-21 23:27:09 +000055
56You will also need the `CMake <http://www.cmake.org/>`_ build system since it
57generates the project files you will use to build with.
58
59If you would like to run the LLVM tests you will need `Python
60<http://www.python.org/>`_. Versions 2.4-2.7 are known to work. You will need
61`GnuWin32 <http://gnuwin32.sourceforge.net/>`_ tools, too.
62
63Do not install the LLVM directory tree into a path containing spaces (e.g.
64``C:\Documents and Settings\...``) as the configure step will fail.
65
66
67Getting Started
68===============
69Here's the short story for getting up and running quickly with LLVM:
70
711. Read the documentation.
722. Seriously, read the documentation.
733. Remember that you were warned twice about reading the documentation.
744. Get the Source Code
75
76 * With the distributed files:
77
78 1. ``cd <where-you-want-llvm-to-live>``
79 2. ``gunzip --stdout llvm-VERSION.tar.gz | tar -xvf -``
80 (*or use WinZip*)
81 3. ``cd llvm``
82
83 * With anonymous Subversion access:
84
85 1. ``cd <where-you-want-llvm-to-live>``
86 2. ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
87 3. ``cd llvm``
88
895. Use `CMake <http://www.cmake.org/>`_ to generate up-to-date project files:
90
91 * Once CMake is installed then the simplest way is to just start the
92 CMake GUI, select the directory where you have LLVM extracted to, and
93 the default options should all be fine. One option you may really
94 want to change, regardless of anything else, might be the
95 ``CMAKE_INSTALL_PREFIX`` setting to select a directory to INSTALL to
96 once compiling is complete, although installation is not mandatory for
97 using LLVM. Another important option is ``LLVM_TARGETS_TO_BUILD``,
98 which controls the LLVM target architectures that are included on the
99 build.
Sean Silva1703e702014-04-08 21:06:22 +0000100 * See the :doc:`LLVM CMake guide <CMake>` for detailed information about
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000101 how to configure the LLVM build.
102
1036. Start Visual Studio
104
105 * In the directory you created the project files will have an ``llvm.sln``
106 file, just double-click on that to open Visual Studio.
107
1087. Build the LLVM Suite:
109
110 * The projects may still be built individually, but to build them all do
111 not just select all of them in batch build (as some are meant as
112 configuration projects), but rather select and build just the
113 ``ALL_BUILD`` project to build everything, or the ``INSTALL`` project,
114 which first builds the ``ALL_BUILD`` project, then installs the LLVM
115 headers, libs, and other useful things to the directory set by the
116 ``CMAKE_INSTALL_PREFIX`` setting when you first configured CMake.
117 * The Fibonacci project is a sample program that uses the JIT. Modify the
118 project's debugging properties to provide a numeric command line argument
119 or run it from the command line. The program will print the
120 corresponding fibonacci value.
121
Aaron Ballman1e9d9b22014-01-23 20:46:44 +00001228. Test LLVM in Visual Studio:
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000123
124 * If ``%PATH%`` does not contain GnuWin32, you may specify
125 ``LLVM_LIT_TOOLS_DIR`` on CMake for the path to GnuWin32.
126 * You can run LLVM tests by merely building the project "check". The test
127 results will be shown in the VS output window.
128
Aaron Ballman1e9d9b22014-01-23 20:46:44 +00001299. Test LLVM on the command line:
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000130
131 * The LLVM tests can be run by changing directory to the llvm source
132 directory and running:
133
134 .. code-block:: bat
135
Aaron Ballmanc8aefe42013-05-01 19:13:50 +0000136 C:\..\llvm> python ..\build\bin\llvm-lit --param build_config=Win32 --param build_mode=Debug --param llvm_site_config=../build/test/lit.site.cfg test
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000137
Aaron Ballmanc8aefe42013-05-01 19:13:50 +0000138 This example assumes that Python is in your PATH variable, you
139 have built a Win32 Debug version of llvm with a standard out of
140 line build. You should not see any unexpected failures, but will
141 see many unsupported tests and expected failures.
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000142
143 A specific test or test directory can be run with:
144
145 .. code-block:: bat
146
Aaron Ballmanc8aefe42013-05-01 19:13:50 +0000147 C:\..\llvm> python ..\build\bin\llvm-lit --param build_config=Win32 --param build_mode=Debug --param llvm_site_config=../build/test/lit.site.cfg test/path/to/test
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000148
149
150An Example Using the LLVM Tool Chain
151====================================
152
1531. First, create a simple C file, name it '``hello.c``':
154
155 .. code-block:: c
156
157 #include <stdio.h>
158 int main() {
159 printf("hello world\n");
160 return 0;
161 }
162
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001632. Next, compile the C file into an LLVM bitcode file:
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000164
165 .. code-block:: bat
166
167 C:\..> clang -c hello.c -emit-llvm -o hello.bc
168
169 This will create the result file ``hello.bc`` which is the LLVM bitcode
Sylvestre Ledru35521e22012-07-23 08:51:15 +0000170 that corresponds the compiled program and the library facilities that
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000171 it required. You can execute this file directly using ``lli`` tool,
172 compile it to native assembly with the ``llc``, optimize or analyze it
173 further with the ``opt`` tool, etc.
174
175 Alternatively you can directly output an executable with clang with:
176
177 .. code-block:: bat
178
179 C:\..> clang hello.c -o hello.exe
180
181 The ``-o hello.exe`` is required because clang currently outputs ``a.out``
182 when neither ``-o`` nor ``-c`` are given.
183
1843. Run the program using the just-in-time compiler:
185
186 .. code-block:: bat
187
188 C:\..> lli hello.bc
189
1904. Use the ``llvm-dis`` utility to take a look at the LLVM assembly code:
191
192 .. code-block:: bat
193
194 C:\..> llvm-dis < hello.bc | more
195
1965. Compile the program to object code using the LLC code generator:
197
198 .. code-block:: bat
199
200 C:\..> llc -filetype=obj hello.bc
201
2026. Link to binary using Microsoft link:
203
204 .. code-block:: bat
205
206 C:\..> link hello.obj -defaultlib:libcmt
207
2087. Execute the native code program:
209
210 .. code-block:: bat
211
212 C:\..> hello.exe
213
214
215Common Problems
216===============
217If you are having problems building or using LLVM, or if you have any other
Sean Silva1703e702014-04-08 21:06:22 +0000218general questions about LLVM, please consult the :doc:`Frequently Asked Questions
219<FAQ>` page.
Michael J. Spencerd93399a2012-06-21 23:27:09 +0000220
221
222Links
223=====
224This document is just an **introduction** to how to use LLVM to do some simple
225things... there are many more interesting and complicated things that you can
226do that aren't documented here (but we'll gladly accept a patch if you want to
227write something up!). For more information about LLVM, check out:
228
229* `LLVM homepage <http://llvm.org/>`_
230* `LLVM doxygen tree <http://llvm.org/doxygen/>`_
231