LLVM-Clang Windows Setup

[I’m posting to the Clang dev list in case anyone else want to add something]

I should get round to finishing that Windows user guide I was writing ;¬)

First, understand that Clang is a sub-project of LLVM, so to get the right build environment first check out LLVM from SVN, then check out Clang into the LLVM tools directory. I’m using RapidSVN for my SVN client, although that is proving fiddly when generating patch files:

http://rapidsvn.tigris.org/

Second, download and install cmake. Once you have LLVM/Clang checked out you can run cmake to create project files for your windows compiler of choice.

http://www.cmake.org/cmake/help/install.html

In theory it should support cygwin, MinGW and multiple Visual Studio versions, although I could not get MinGW to configure neatly for me.

If you don’t have any of these compilers, you can download the Visual C++ Express edition – that is that I am using <g>. The cmake project generated for Visual Studio 2008 works just fine with the express edition.

Finally, some of the cmake tools seem to want Perl and Python to be available so I downloaded and set those up too, although I seem to have a working system despite not having these tools in the path when running cmake, so maybe those are optional?

http://strawberryperl.com/

For my needs I am purely developing the C++ aspects of Clang, which are essentially running syntax checks only on my test files. I have not yet got Clang/LLVM linking and running C programs because I have not had the need to yet. Also, I am not getting automated running of the test suite yet.

One final hint – when running clang compiler from the command line prompt it is useful to run the command

  chcp 65001

This sets your console to use UTF-8 as its code page, which will correctly display any messages using characters outside the 7-bit ASCII range – typically found in string literals.

AlisdairM

[I’m posting to the Clang dev list in case anyone else want to add something]

I should get round to finishing that Windows user guide I was writing ;¬)

That would be great!

First, understand that Clang is a sub-project of LLVM, so to get the right build environment first check out LLVM from SVN, then check out Clang into the LLVM tools directory. I’m using RapidSVN for my SVN client, although that is proving fiddly when generating patch files:

http://rapidsvn.tigris.org/

I typically recommend TortoiseSVN:

  http://tortoisesvn.tigris.org/

Finally, some of the cmake tools seem to want Perl and Python to be available so I downloaded and set those up too, although I seem to have a working system despite not having these tools in the path when running cmake, so maybe those are optional?

http://strawberryperl.com/
Download Python | Python.org

Clang's regression testing uses Python. Perl is only needed for building llvm-config, which is generally pointless on Windows.

For my needs I am purely developing the C++ aspects of Clang, which are essentially running syntax checks only on my test files. I have not yet got Clang/LLVM linking and running C programs because I have not had the need to yet.

Clang doesn't have support for the Windows ABI, so you won't be able to execute Clang-built programs on Windows.

Also, I am not getting automated running of the test suite yet.

That's the Python bit, although I don't know if anyone's tried it :slight_smile:

  - Doug

Adding a Windows section to the Getting Started page would be very helpful. Also some tips on using svn would help those of us new to it. Some of this I was able to glean or at least be hinted at in the LLVM docs (i.e. http://llvm.org/docs/GettingStartedVS.html), but it was kind of hard to find, and possibly not entirely up-to-date, so gathering it in one place would be helpful. Some tidbits from my experience:

  1. Basically, I found that only running “cmake .” at the top level LLVM directory is the only usage that worked for me. This creates the project and solution files for Visual Studio, apparently for VS2005
  2. To use VS, load the LLVM.sln file in the llvm top level directory.
  3. To build the clang front end, build clang-cc. (Initially, I tried building and running the “clang” project, which apparently is the compiler driver, but for just running the clang front end, clang-cc is all you need. At the time, I couldn’t get the driver to work for me, always giving some error, and then I found I could just run clang-cc. Building the “ALL-BUILD” project actually just worked for me for the first time, which builds the llvm stuff too, but clang-cc has been enough for my front-end work.)
  4. After doing the initial checkout (“svn co (trunk) (dir)” of both the llvm and clang repositories), thereafter you can just run “svn update” to update your existing tree to the latest. Note that you have to do it for both the llvm and llvm\tools\clang directories seperately. If you made changes, it will also perform merges. During the update, a letter preceding the file name in the output gives the status of each file. It would be very helpful to read at least the “Basic Usage” chapter in the svn docs, especially if you need to resolve conflicts (“C” status).
  5. To make patches, I created the following batch file:
    rem Create a diff file for Clang. Usage: clangdiff (llvm path) (patch name)
    svn diff -x -u %1 >(put your patch output dir here)%2
    Note that the paths embedded in the patch depend on where you run it, so I usually cd to the llvm directory and use tools/clang for the first argument to cover all of clang.

I’m currently trying to figure out how to run the tests. I’m guessing you just build the “clang-test” project, but I’m gettting errors in the python stuff. I’ll put this in a separate message to keep this one focused on the Windows setup.

-John