Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. I used the following method to compile clang for C++ on Windows 7:
  2.  
  3. 1. Download and install MinGW (make sure you install the C++ compiler) and put the bin folder in your PATH (I have MinGW 4.6.1 and tested successfully on another computer with 4.6.2)
  4. 2. Make sure you have Python in your PATH (not 3, I have 2.7)
  5. 3. Make sure you have Perl in your PATH (I used ActivePerl 5.14.2 64-bit)
  6. 4. Get CMake and put it in your PATH
  7. 5. Go to the LLVM downloads page (http://llvm.org/releases/download.html) and download the LLVM 3.0 source code along with the Clang source code. Don't get the code from the SVN, it doesn't work with the MinGW headers.
  8. 6. Extract the source codes; I had the llvm source in a folder named llvm-3.0.src on my desktop
  9. 7. Put the clang source directly in a folder called "clang" (it must be called this exactly or you will build llvm but clang won't get built) in the "tools" folder inside the llvm source folder
  10. > this should make your directories look like
  11. - llvm source
  12. - autoconf folder
  13. - ...
  14. + tools folder
  15. - ...
  16. + clang folder
  17. - bindings folder
  18. - ...
  19. - Makefile file
  20. - ...
  21. - ...
  22. - ...
  23. 8. Make a folder named "build" in the same directory as the llvm source folder
  24. 9. Open a command line and cd into the build folder
  25. 10. Run the command
  26.  
  27. cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..\llvm-3.0.src
  28.  
  29. (the last argument is the relative path to the folder that has the llvm source in it (and the clang source in the tools/clang subdirectory))
  30.  
  31. This will do the equivalent of a "configure" command, and the makefiles and everything will be generated in the build folder
  32. This will take a few minutes
  33.  
  34. 11. Run the command
  35.  
  36. mingw32-make
  37.  
  38. This will compile llvm and clang, and the clang executables will be generated in the build/bin folder
  39. This will probably take a long time. It might be good to close all other programs so that your computer can concentrate, and so they don't interfere with the lengthy compilation process, such as putting a lock on a folder that the compiler is writing to (it happened to me). I even turned off my antivirus and firewall software so that they wouldn't try to scan the generated files and get in the way.
  40.  
  41. Time for testing it out
  42.  
  43. 1. Create a .cpp file in the build/bin folder (I will use hello.cpp). Use a standard library header to make sure the include paths and libraries are working. Start with a very simple program.
  44.  
  45. (What I started with:
  46. #include <iostream>
  47.  
  48. int main() {
  49. std::cout << "hi";
  50. }
  51. )
  52.  
  53. 2. Run the command
  54.  
  55. clang hello.cpp -std=c++0x -I"C:\MinGW\lib\gcc\mingw32\4.6.1\include\c++" -I"C:\MinGW\lib\gcc\mingw32\4.6.1\include\c++\mingw32" -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.1 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../.. -L/mingw/lib -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt
  56.  
  57. (-L specifies a directory in which to search for libraries and -l specifies a library to link)
  58. (If you do not have MinGW installed to the same path as I did, you can find out the paths with the command "g++ somefile.cpp -v" to get g++ to spill its guts about what options it is using for the library paths and library files and everything else
  59. Search near the end of the output for the -L and -l options. Be aware of the .o file names that are interspersed with the -L's. Clang uses many of the same options as g++ so I literally copied and pasted that line from the output of g++)
  60.  
  61. This should compile your program and produce a file named a.out
  62.  
  63. 3. rename a.out to a.exe or whatever
  64. 4. Run the .exe
  65. 5. Your program should run.
  66.  
  67. > Clang still has some problems on Windows (I don't know if these problems are also on linux). For example, compiling a lambda (which clang doesn't support) with -std=c++0x will cause clang to crash and emit a diagnostic error.
  68. (I was informed on the LLVM IRC that this is because clang implements parsing for lambdas but not semantic analysis, which is the phase in which it crashes (because they forgot to disable parsing lambdas for the 3.0 release), and they already know about this bug)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement