Use mingw to compile clang

Source: Internet
Author: User

Recently, I have read several articles that clang is good, and I am tempted to find it on the Internet based on GCC's experience in Windows. The results are nothing. However, you can see in the llvm official documentation (http://clang.llvm.org/get_started.html)
"On Unix-like systems", so I decided to compile a Windows clang.

Step 1: Installation environment

Follow the http://clang.llvm.org/get_started.html prompts to start the next mingw (www.mingw.org /)
The mingwused in this tutorial is mingw-get-inst-2012020..exe and GCC 4.6.2. When all the packages are downloaded, check whether you can click mingw-get-inst-2012020..exe or use more methods to download mingw \ var \ Lib \ mingw-Get \ data
Directory, where mingw is your installation directory. Other you also need to download Python (http://www.python.org/ftp/python/), and
Groff (http://sourceforge.net/projects/mingw/files/MSYS/Extension/groff/. lzma ", I decompress them (You may be working on
7zip www.7-zip.org/) to the mingw \ msys. After the installation is complete, start mingw shell. Go to mingw \ msys \ 1.0 \ home \ Administrator (Administrator
For your current doneiws user ). You can also compile it in other directories, such as c: \ llvm. You need CD/C/llvm, e disk,/e/, and so on. It is case-insensitive.

Step 2: Check out llvm code:

SVN Co http://llvm.org/svn/llvm-project/llvm/trunk llvm.

Step 3: Check out clang:

Directory switch to llvm/tools. llvm is the source code root directory.

Check out the svn Co http://llvm.org/svn/llvm-project/cfe/trunk clang.

Step 4:Check out compiler-RT

Directory switch to llvm/projects. llvm is the source code root directory.
SVN Co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-RT
Step 5: Compile llvm and clang:

This step is not the same as the http://clang.llvm.org/get_started.html prompt, if it is done as prompted, it will be compiled
Debug, almost 10 Gb. I was shocked by the compilation that day. How could it be so big. But I thought it was wrong. I installed clang packages in Ubuntu, less than 100 MB. Later, I found the materials on its official website. There were three ways to publish the materials. One is debug + asseerts, the other is release + asserts, and the third is release, which accounts for the smallest capacity. It seems that clang Compilation speed is much faster, this is the case.

So use./configure -- prefix =/mingw -- enable-optimized -- disable-assertions to pay attention to the previous ./
Similar to running files in Linux

Command explanation: -- prefix =/mingw. I have tried it. This stuff must be placed in the mingw root directory. Elsewhere, clang will prompt that the header file cannot be found. If you have other methods, hope to share it. -- Enable-optimized
-- Disable-assertions will be compiled into the release version, which is small. But I don't know what to do with release + asserts. If you know it, please let me know. Thank you.

Then use make for compilation, and then use make install to install it to mingw. You can also use make install
Destdir =/local (/local will be installed in mingw \ msys) to other directories, back up them (if the backup is under/local, remember to delete it after the backup is complete, so as not to affect the clang operation). In the future, you need to re-compile the code, and directly overwrite the code to the mingw directory during reinstallation.

Last step:Check whether the installation is successful or not. Otherwise, it will be wasted.

Write hello. c

# Include <stdio. h>

Int main ()

{

Printf ("Hello Clang !! ");

Return 0;

}


If clang-V hello. C is used, the compilation and installation are successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.