Clang on windows mingw

Installing clang++ to compile and link on Windows : Part 2

01 Sep 2015

Part 1 : The Problem
Part 2 : Approach 1 — Clang 3.7
Part 3 : Approach 2 — MSYS2

Approach 1 — Clang 3.7

In this approach we’ll be installing Clang 3.7.0 and gcc 5.1.0 (via MinGW-w64), to allow us to build and link with clang from the standard windows command prompt.

First quickly consider the following:

  • This tutorial was created for, and tested with windows 8.1 — I can’t make promises how well it will work on windows 10.
  • If you have an older version of clang/LLVM installed, please use its uninstaller before continuing. Make sure that neither C:\Program Files\LLVM or C:\Program Files (x86)\LLVM exist on your machine.
  • You’ll need to edit your system PATH, and the standard windows UI for it is pretty awful. You should consider grabbing the free Windows Environment Variable Editor or “Eveditor”: http://eveditor.com/ which is more user friendly and shows you if you have invalid paths set.
  • You will also need to be able to open .7z archives, so make sure to install 7zip or something similar.

Ok, let’s get to the fun part. You will need to install all of the following:

  1. Clang for 64 bit
    • Download Link — clang 3.7.0 64 bit.
    • Run the installer. When you get to the PATH settings, make sure to add LLVM to the system PATH:
    • Use the default install location: C:\Program Files\LLVM . Once the installation completes hit ‘Finish’.
    • clang++.exe should be located in C:\Program Files\LLVM\bin , which should be in your system PATH.
  2. Clang for 32 bit
    • Download Link — clang 3.7.0 32 bit.
    • Run the installer. IMPORTANT: because we technically just installed a different version of LLVM, the installer will see the 64 bit version as an ‘older version’ and will give you this warning: You will want to click ‘No’, so that the 64 bit version doesn’t get uninstalled. We want both the 32 and the 64 bit versions.
    • You will once again be prompted to add LLVM to the path. This time leave it set to Do not add LLVM to the system PATH .
    • Use the default install location: C:\Program Files (x86)\LLVM and complete the installation.
    • clang++.exe should be located in C:\Program Files (x86)\LLVM\bin , but should NOT be in your system path.
  3. MinGW-w64 for 64 bit
    • Download Link — MinGW-w64: 64 bit, version 5.1.0 with posix threads and seh exceptions.
    • Extract the x86_64….7z file, either to your desktop (and move it), or directly to your C: Drive:
    • Once done you should be able to find g++.exe in C:\mingw64\bin — you cannot change this location because Clang has it hardcoded.
    • Add C:\mingw64\bin to your system PATH.
  4. MinGW-w64 for 32 bit
    • Download Link — MinGW-w64: 32 bit, version 5.1.0 with posix threads and dwarf exceptions.
    • Extract the x686….7z file, either to your desktop (and move it), or directly to your C: Drive.
    • Once done you should be able to find g++.exe in C:\mingw32\bin
    • Do NOT add mingw32 to your path!
  5. Batch files
    • The 64 bit version of clang/g++ will be used by default. If you want to use the 32 bit versions you can temporarily modify your path with these batch files:
    • Right click view raw and save setgcc32.bat and setgcc64.bat :
    • Both batch files should be in a folder on the PATH. For example, create C:\Utils , place the batch files in there and add C:\Utils to your path.
Читайте также:  Что такое виндовс линукс

And that’s it! At this point, you should have the 32 bit and 64 bit versions of Clang 3.7.0 and MinGW-w64 5.1.0 installed. You can now compile 64 bit windows applications through clang like this:

And if you need to compile to 32 bit, just run the batch script, which will temporarily modify your path to prefer the 32 bit versions:

Note: If you see a fatal error that some common library cannot be found when you try to compile, such as:

Tutorial: Configure CLion on Windows

On Windows, configuring CLion requires setting up the environment: Cygwin, MinGW, WSL, or Microsoft Visual C++. You can have several environments installed on your system and create separate CLion toolchains for each of them. As a determining part of a toolchain, the environment provides C and C++ compilers, the make utility, and the debugger (in case of using default tools).

For details on Remote Host toolchains, see Full Remote Mode.

MinGW

MinGW-w64 (64- and 32-bit)

Download and run the MinGW-w64 installer. It provides both 64- and 32-bit options.

In the MinGW-w64 installation wizard, make sure to select the required architecture. Note that the default suggested option is 32-bit.

Once the installation is finished, open CLion and go to File | Settings | Build, Execution, Deployment | Toolchains .

Choose the MinGW toolchain that you want to configure or create a new one using the icon.

CLion will attempt to detect the MinGW installation automatically. Check the detection result in the Environment field, and specify the path manually if required.

Wait until the tools detection finishes.

Select the Debugger : you can use either MinGW-w64 GDB or a custom GDB binary.

Click Apply when all the tools are set correctly.

MinGW (32-bit only)

Although MinGW-w64 provides both 64- and 32-bit options, you can also install MinGW, the 32-bit-only version.

In the MinGW installation wizard, select the following packages from the Basic Setup list: mingw-developer-tool , mingw32-base , mingw32-gcc-g++ , mingw32-msys-base .

When configuring the toolchain, if CLion cannot detect compilers or make , double-check the installed packages in MinGW Installation Manager .

In the Debugger field, you can choose between the bundled GDB, MinGW GDB, or your custom GDB executable.

Читайте также:  Конвейер команд windows это

The recommended option is bundled GDB, since it is guaranteed to include Python support required for CLion data renderers.

Cygwin

Download the Cygwin installer, version 2.8 or later.

Run the installer and select the following packages:

  • gcc-g++
  • make
  • gdb

To select a package, type its name in the Search field and then click it in the list until a tick mark appears in the Bin? column:

Once the installation is finished, open CLion and go to File | Settings | Build, Execution, Deployment | Toolchains . Choose the toolchain that you want to configure.

Select Cygwin from the Environment list. CLion will attempt to detect the Cygwin installation automatically. Check the detection result, and specify the path manually if required.

Wait until the tools detection finishes, and press Apply .

Windows Subsystem for Linux

You can use WSL, Windows Subsystem for Linux, as your working environment in CLion on Windows 10 (starting the Fall Creators Update version 1709, build 16299.15).

WSL toolchain enables you to build projects using CMake and compilers from Linux and run/debug on WSL without leaving CLion running on your Windows machine.

Refer to our WSL guide for details on setting up WSL on your system and configuring WSL toolchains in CLion.

Microsoft Visual C++

Install Visual Studio 2013, 2015, 2017, or 2019 on your system.

In CLion, go to File | Settings | Build, Execution, Deployment | Toolchains .

Click and select Visual Studio from the list of toolchain templates.

Check the Environment field. CLion will attempt to automatically detect the installed Visual Studio distribution. If the detection fails, set the path to Visual Studio manually.

If required, specify the Architecture ( x86 , amd64 , x86_arm , or another), Platform ( store , uwp , onecore , or leave it blank), and Version . To build your project for the selected architecture, CLion will call the script to configure the environment with the specified parameters.

If the version of your compiler toolset is earlier than the version of your Visual Studio installation, pass it in the Version field via the vcvars_ver flag, for example, -vcvars_ver=14.16 .

Wait until the tools detection is finished:

MSVC compiler

CLion supports the Microsoft Visual C++ compiler that ships with Visual Studio 2013, 2015, 2017, and 2019.

Note that msbuild is not supported: CLion runs CMake with the NMAKE generator instead.

For the case when your code includes MSVC extensions, CLion provides the support for:

__uuidof , __forceinline , __unaligned , and __alignof keywords;

pointer type attributes: __ptr32 , __ptr64 , __uptr , __sptr ;

MSVC built-in data types: (unsigned) __int8 , (unsigned) __int16 , (unsigned) __int32 , (unsigned) __int64 , __wchar_t ;

additional format specifiers, such as %I32 and %I64 ;

the clang ‘s -fms-extensions flag.

Clang-cl compiler

As an alternative compiler, you can use clang-cl- the MSVC-compatible compiler driver for Clang. CLion supports clang-cl version 8.0 and later.

Install clang-cl from the LLVM site or along with the Visual Studio tools.

When installed from the LLVM site, the clang-cl binary can be found at the standard location C:\Program Files\LLVM\bin\clang-cl.exe for the 64-bit version or C:\Program Files (x86)\LLVM\bin\clang-cl.exe for the 32-bit version.

Читайте также:  User friendly linux 2021

In CLion, go to File | Settings | Build, Execution, Deployment | Toolchains and select the Visual Studio toolchain that you want to configure, or create a new one.

Point the C Compiler and C++ Compiler fields to clang-cl.exe . CLion will suggest the paths detected automatically.

Note that currently the -T clangcl options can’t be picked up if the bundled CMake is in use along with the Visual Studio toolchain setup (CPP-18848 ).

LLDB-based MSVC debugger

The MSVC toolchain debugger is implemented on top of LLDB. It can work with native visualizers from the Visual Studio installation or from your project. To enable native visualizers support and set the desired diagnostics level, select Enable NatVis renderers for LLDB in Settings | Build, Execution, Deployment | Debugger | Data Views | C/C++ :

Also, if you have custom native visualizers in your project, CLion will use them as well:

Clang compiler on Windows

With CMake 3.15, it has become possible to use the Clang compiler on Windows with the MinGW-w64/MinGW toolchain.

However, the LLVM Clang for Windows is built using Microsoft Visual Studio, and all the built-in macros and include search paths are set up for use with Visual Studio. So if you take Clang from the LLVM repository, it will not work correctly when configured with the MinGW toolchain. One of the possible workarounds is described below.

Set up the Clang compiler for MinGW

Download the following packages with the pacman tool (use the pacman -S package_name command):

Как заставить Clang использовать MinGW по умолчанию?

Пытаемся подружить clang 3.6 и Code::Blocks 13.12 + MinGW под Windows 7
Скачал clang. Установил в корень диска С. То есть, путь получился такой: До этого у меня уже был.

Как использовать переменных среды linux в clang программе?
Собственно, нужно что бы моя программка вывела значение переменной LOGNAME. Для баша я знаю как, а.

Как заставить кнопки отображаться стилем Win7? (MinGW)
Приветствую всех. Пишу на C++ (WinAPI). Компилятор — MinGW. Появилась следующая проблема: В.

Как заставить Twebbrowser использовать Javascript
Как заставить Twebbrowser использовать Javascript и в какой процедуре вызвать эту Javascript-функцию

Заказываю контрольные, курсовые, дипломные и любые другие студенческие работы здесь или здесь.

Mingw пути включаемых файлов и библиотек по умолчанию
Здравствуйте! Решил попробовать поработать с кросс-платформенным компилятором gcc в Windows. Для.

Как заставить ноутбук использовать интергрированную видеокарту?
Есть ноут Asus k401L. Соответственно у него две видеокарты: встроенная от Intel и дискретная от.

Как заставить Postgres использовать определенный индекс
Есть запрос SELECT DISTINCT «Field1» FROM «Table» WHERE «Field2» LIKE ‘val1%’ AND.

Как заставить Resident Evil 5 использовать лицензию?
Установил RESIDENT EVIL 5(лицензия),но при запуске игры,запускается другая игра которая уже стояла.

Как заставить виртмашину использовать максимум разрешения экрана
Установил ВиртБокс. На него W7. все пашет, но . Разрешение экрана минимальное. 600*900 что ли.

Как заставить программу использовать больше ресурсов процессора?
Возможно ли вообще, в принципе, заставить программу использовать больше ресурсов процессора? Как.

Оцените статью