Clion Open Sln

This page gives you the shortest path to checking out Clang and demos a fewoptions. This should get you up and running with the minimum of muss and fuss.If you like what you see, please consider gettinginvolved with the Clang community. If you run into problems, please filebugs in LLVM Bugzilla.

  1. Once you've got your compiler and source program ready, it is very easy to compile and run a C program. Assuming that you've installed GCC compiler, and you have a source.cpp file that you want to compile, follow the following instructions to compile and run it.
  2. @Viachaslau, thanks a lot for the clarification! Unfortunately, I didn't managed to reproduce the issue on my side (CLion 2018.2.4, Windows 10, MSVC toolchain, bundled CMake).

Release Clang Versions

In some blogs, e.g., this one, said that we should compile it under./src/ and needed to change the./scr/CMakeLists.txt, which is quite complex I thought. Actually, we can simple open the whole root directory, then it will be automatically compiled with this info. My Rec ommendation for CodeLite. My Recommendation for CodeLite. 9 Pros 7 Cons 1.

Clang is released as part of regular LLVM releases. You can download the release versions from https://llvm.org/releases/.

Clang is also provided in all major BSD or GNU/Linux distributions as part of their respective packaging systems. From Xcode 4.2, Clang is the default compiler for Mac OS X.

Building Clang and Working with the Code

Open

On Unix-like Systems

If you would like to check out and build Clang, the current procedure is asfollows:

  1. Get the required tools.
    • See Getting Started with the LLVM System - Requirements.
    • Note also that Python is needed for running the test suite. Get it at: https://www.python.org/downloads/
    • Standard build process uses CMake. Get it at: https://cmake.org/download/
  2. Check out the LLVM project:
    • Change directory to where you want the llvm directory placed.
    • git clone https://github.com/llvm/llvm-project.git
    • The above command is very slow. It can be made faster by creating a shallow clone. Shallow clone saves storage and speeds up the checkout time. This is done by using the command:
      • git clone --depth=1 https://github.com/llvm/llvm-project.git (using this only the latest version of llvm can be built)
      • For normal users looking to just compile, this command works fine. But if someone later becomes a contributor, since they can't push code from a shallow clone, it needs to be converted into a full clone:
        • cd llvm-project
        • git fetch --unshallow
  3. Build LLVM and Clang:
    • cd llvm-project
    • mkdir build (in-tree build is not supported)
    • cd build
    • cmake -DLLVM_ENABLE_PROJECTS=clang -G 'Unix Makefiles' ../llvm
    • make
    • This builds both LLVM and Clang for debug mode.
    • Note: For subsequent Clang development, you can just run make clang.
    • CMake allows you to generate project files for several IDEs: Xcode, Eclipse CDT4, CodeBlocks, Qt-Creator (use the CodeBlocks generator), KDevelop3. For more details see Building LLVM with CMake page.
  4. If you intend to use Clang's C++ support, you may need to tell it how to find your C++ standard library headers. In general, Clang will detect the best version of libstdc++ headers available and use them - it will look both for system installations of libstdc++ as well as installations adjacent to Clang itself. If your configuration fits neither of these scenarios, you can use the -DGCC_INSTALL_PREFIX cmake option to tell Clang where the gcc containing the desired libstdc++ is installed.
  5. Try it out (assuming you add llvm/build/bin to your path):
    • clang --help
    • clang file.c -fsyntax-only (check for correctness)
    • clang file.c -S -emit-llvm -o - (print out unoptimized llvm code)
    • clang file.c -S -emit-llvm -o - -O3
    • clang file.c -S -O3 -o - (output native machine code)
  6. Run the testsuite:
    • make check-clang

Using Visual Studio

The following details setting up for and building Clang on Windows usingVisual Studio:

  1. Get the required tools:
    • Git. Source code control program. Get it from: https://git-scm.com/download
    • CMake. This is used for generating Visual Studio solution and project files. Get it from: https://cmake.org/download/
    • Visual Studio 2017 or later
    • Python. It is used to run the clang test suite. Get it from: https://www.python.org/download/
    • GnuWin32 tools The Clang and LLVM test suite use various GNU core utilities, such as grep, sed, and find. The gnuwin32 packages are the oldest and most well-tested way to get these tools. However, the MSys utilities provided by git for Windows have been known to work. Cygwin has worked in the past, but is not well tested. If you don't already have the core utilies from some other source, get gnuwin32 from http://getgnuwin32.sourceforge.net/.
  2. Check out LLVM and Clang:
    • git clone https://github.com/llvm/llvm-project.git

    Note: Some Clang tests are sensitive to the line endings. Ensure that checking out the files does not convert LF line endings to CR+LF. If you're using git on Windows, make sure your core.autocrlf setting is false.

  3. Run CMake to generate the Visual Studio solution and project files:
    • cd llvm-project
    • mkdir build (for building without polluting the source dir)
    • cd build
    • If you are using Visual Studio 2017: cmake -DLLVM_ENABLE_PROJECTS=clang -G 'Visual Studio 15 2017' -A x64 -Thost=x64 ..llvm
      -Thost=x64 is required, since the 32-bit linker will run out of memory.
    • To generate x86 binaries instead of x64, pass -A Win32.
    • See the LLVM CMake guide for more information on other configuration options for CMake.
    • The above, if successful, will have created an LLVM.sln file in the build directory.
  4. Build Clang:
    • Open LLVM.sln in Visual Studio.
    • Build the 'clang' project for just the compiler driver and front end, or the 'ALL_BUILD' project to build everything, including tools.
  5. Try it out (assuming you added llvm/debug/bin to your path). (See the running examples from above.)
  6. See Hacking on clang - Testing using Visual Studio on Windows for information on running regression tests on Windows.

Using Ninja alongside Visual Studio

We recommend that developers who want the fastest incremental builds use theNinja build system. You can use thegenerated Visual Studio project files to edit Clang source code and generate asecond build directory next to it for running the tests with these steps:

Clion Open Sln File

  1. Check out clang and LLVM as described above
  2. Open a developer command prompt with the appropriate environment.
    • If you open the start menu and search for 'Command Prompt', you should see shortcuts created by Visual Studio to do this. To use native x64 tools, choose the one titled 'x64 Native Tools Command Prompt for VS 2017'.
    • Alternatively, launch a regular cmd prompt and run the appropriate vcvarsall.bat incantation. To get the 2017 x64 tools, this would be:
      'C:Program Files (x86)Microsoft Visual Studio2017CommunityVCAuxiliaryBuildvcvarsall.bat' x64
  3. mkdir build_ninja (or build, or use your own organization)
  4. cd build_ninja
  5. set CC=cl (necessary to force CMake to choose MSVC over mingw GCC if you have it installed)
  6. set CXX=cl
  7. cmake -GNinja ..llvm
  8. ninja clang This will build just clang.
  9. ninja check-clang This will run the clang tests.

Clion Openssl

Clang Compiler Driver (Drop-in Substitute for GCC)

The clang tool is the compiler driver and front-end, which isdesigned to be a drop-in replacement for the gcc command. Here aresome examples of how to use the high-level driver:

The 'clang' driver is designed to work as closely to GCC as possible to maximize portability. The only major difference between the two is that Clang defaults to gnu99 mode while GCC defaults to gnu89 mode. If you see weird link-time errors relating to inline functions, try passing -std=gnu89 to clang.

Examples of using Clang