Use any C++ Compiler with Visual Studio

Microsoft Visual Studio 2017 supports several C++ compilers to suit a wide variety of codebases. In addition to the Microsoft Visual C++ compiler that many of you are likely familiar with, Visual Studio 2017 also supports Clang, GCC, and other compilers when targeting certain platforms.
This post is intended to familiarize you with the variety of C++ compilers that are compatible with the Visual Studio IDE, and to understand when they might be applicable to use with your projects. Some compilers may be better suited to your needs depending on your project or target. Alternatively, you may be interested in checking out new language features, such as C++ Concepts, that are not available across all compilers without needing to leave the IDE.
You can select the compiler and corresponding toolset that will be used to build a project with the “Platform Toolset” property under General Configuration Properties for C++ projects. Any installed compilers that are applicable to your project type will be listed in the “Platform Toolset” dropdown.
Microsoft C++ Compiler (MSVC)
If you are targeting Windows, the Microsoft C++ compiler (MSVC) may be the way to go. This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.

Compiler options for the Microsoft C++ compiler.
Clang
You can use the Clang compiler with Visual Studio to target Android, iOS, and Windows.
If you are targeting Android, you can use the Clang/LLVM compiler that ships with the Android NDK and toolchain to build your project. Likewise, Visual Studio can use Clang running on a Mac to build projects targeting iOS. Support for Android and iOS is included in the “Mobile Development with C++” workload. For more information about targeting Android or iOS check out our posts tagged with the keywords “Android” and “iOS”.
If you are targeting Windows, you have a few options:
- Use Clang/LLVM; “Clang for Windows” includes instructions to install Clang/LLVM as a platform toolset in Visual Studio.
- Use Clang to target Windows with Clang/C2 (Clang frontend with Microsoft Code Generation).

Compiler options for the Clang/C2 compiler.
It might make sense to use Clang/C2 if you want to bring a codebase that takes advantage of Clang’s language features to the Windows platform. Since the code generation and optimization is handled by the MSVC backend, binaries produced by Clang/C2 are fully compatible with binaries produced by MSVC. You can learn more about Clang/C2 from Clang with Microsoft Codegen – or check out the latest updates in posts tagged with the keyword “clang”.
If your project targets Linux or Android, you can consider using GCC. Visual Studio’s C++ Android development natively supports building your projects with the GCC that ships with the Android NDK, just like it does for Clang. You can also target Linux – either remotely or locally with the Windows Subsystem for Linux – with GCC.

Compiler options for GCC.
Check out our post on Visual C++ for Linux Development for much more info about how to use Visual Studio to target Linux with GCC. If you are specifically interested in targeting WSL locally, check out Targeting WSL from Visual Studio.
Closing
Visual Studio also makes use of the Edison Design Group (EDG) frontend to provide flexible IntelliSense regardless of whether you use MSVC, Clang, or GCC to build your code. Visual Studio gives you access to a wide range of choices when it comes to C++ compilers. This way you can make sure that as you develop your code, it continues to compile against all major compilers.
Install Visual Studio today and give it a try. Please let us know if we have missed any compilers you use, and share your feedback as we look forward to improving your C++ development experience.
Какой компилятор в visual studio
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
![]()
- ProfileText
- Sign in
Answered by:
Question
Answers
The compiler will predefine some macros that you can detect to determine which compiler you are using.
For example, Microsoft Visual C++ is defining _MSC_VER to a value:
You should be able to make use of something like #ifdef _MSC_VER and #if _MSC_VER > 1400 or whatever your specific needs are.
You can also detect symbols like __WIN32__ to detect if you are in a Windows build environment. Some compilers will define __unix__ or __APPLE__ if your build environment is of that variety.
How to Detect if I'm Compiling Code with a particular Visual Studio version?
Is there any way to know if I’m compiling under a specific Microsoft Visual Studio version?
7 Answers 7
_MSC_VER and possibly _MSC_FULL_VER is what you need. You can also examine visualc.hpp in any recent boost install for some usage examples.
Some values for the more recent versions of the compiler are:
The version number above of course refers to the major version of your Visual studio you see in the about box, not to the year in the name. A thorough list can be found here. Starting recently, Visual Studio will start updating its ranges monotonically, meaning you should check ranges, rather than exact compiler values.
cl.exe /? will give a hint of the used version, e.g.:
Yep _MSC_VER is the macro that’ll get you the compiler version. The last number of releases of Visual C++ have been of the form <compiler-major-version>.00.<build-number> , where 00 is the minor number. So _MSC_VER will evaluate to <major-version><minor-version> .
You can use code like this:
It appears updates between successive releases of the compiler, have not modified the compiler-minor-version , so the following code is not required:
Access to more detailed versioning information (such as compiler build number) can be found using other builtin pre-processor variables here.
Установка поддержки C++ в Visual Studio Code (VSCode)
Для разработки программ на языке c++ вы можете использовать среду разработки Visual Studio Code (VSCode).
Сегодня мы рассмотрим установку поддержки языка программирования с++ в этой IDE.
Выбор компилятора
Перед установкой расширения для поддержки с++ в VSCode нам нужно сначала определиться какой компилятор использовать.
Под Windows существует несколько возможностей:
- Вы можете использовать Windows Subsystem for Linux (WSL) и установив в виртуальной машине все необходимые пакеты компилировать программы с помощью специального расширения для VSCode.
- Вы можете установить MinGW или MSYS2 и использовать их компиляторы.
- Вы можете установить компилятор Microsoft C++ compiler (MSVC)
Сегодня мы рассмотрим самый простой способ – установку Microsoft C++ compiler (MSVC).
Установка Microsoft C++ compiler (MSVC)
Для начала скачаем установщик по ссылке:
Скачиваем файл, в моем случае он называется:
Запускаем, откроется окно:

Нажимаем «Продолжить» и ждем, пока не закончиться скачивание файлов:

После этого откроется окно:

Поставьте галочку рядом с Разработка классических приложений на C++

К сожалению, нет способа не ставить саму IDE.
Снимите галочки с:
- Live Share
- С++ AddressSanitizer
- Адаптер тестов для Boost.Test
- Адаптер тестов для Google Test

Ожидайте окончания установки.
После окончания загрузок перезагрузите ваш ПК
Проверка доступности компилятора
После перезагрузки проверим доступен ли компилятор, для этого запустите cmd.exe скопируйте и вставьте в консоль строку
Будет запущена консоль разработчика:
Компилятор успешно установлен и доступен.
Теперь пришло время установить расширение для поддержки с++ в VSCode.
Установка расширения для поддержки С++ в VSCode
Откроется панель Extensions: Marketplace – это каталог, из которого мы можем скачать все необходимые расширения и темы, достаточно знать их название.


Выберите указанный пункт и нажмите install

Будет начато скачивание дополнительных компонентов. После окончания загрузок расширение будет готово к использованию.
Настройка VSCode для использования компилятора MSVC
Для того, чтобы протестировать работу компилятора создадим тестовый проект.
Для нормального функционирования компилятора MSVC нужно установить несколько переменных окружения. Чтобы упростить задачу воспользуемся Visual Studio 2019 Developer Command Prompt.
Запустите его из меню Пуск введя слово developer, откроется консоль:

Допустим, наши проекты буду находится в папке d:\cpp
Создадим данную папку и перейдем в нее:
Создадим папку для проекта test
Запустим VSCode из этой папки
Откроется окно VSCode

Обратите внимание наша папка уже открыта.
Добавим новый файл для этого нажмите на кнопку:

В появившееся поле введите имя файла main.cpp
Введите текст программы и не забудьте сохранить результат:
Настройка компилятора для проекта
Теперь у нас есть программа, осталось её скомпилировать, давайте настроим задачу сборки для проекта.
Настройка задачи сборки (Build Task)
Выберите пункт меню Terminal –> Configure Default Build Task…

В окне выберите – cl.exe
Будет создан файл сборки:

Закройте вкладку с файлом tasks.json
Откройте файл main.cpp и нажмите

Сборка успешно завершена.
Щёлкните мышкой по терминалу и нажмите пробел, чтобы закрыть результаты сборки.
Введите main.exe и нажмите Enter

Поздравляю, мы успешно настроили среду разработки VSCode для работы с языком программирования C++.
Заключение
Сегодня мы добавили поддержку языка программирования C++ в среду разработки VSCode.
Нами был установлен компилятор Microsoft C++ compiler (MSVC) и проверена его работоспособность.
Мы добавили тестовый проект и настроили задачу сборки Build Task для нашего проекта.