# Unable to set compiler using windows

**URL:** https://discourse.cmake.org/t/unable-to-set-compiler-using-windows/8137
**Category:** Usage
**Created:** [May 16, 2023, 7:01pm UTC](https://discourse.cmake.org/t/unable-to-set-compiler-using-windows/8137 "2023-05-16T19:01:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rbartling](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/5f8ce5/32.png) [@rbartling](https://discourse.cmake.org/u/rbartling)
#### Post date: [May 16, 2023, 7:01pm UTC](https://discourse.cmake.org/t/unable-to-set-compiler-using-windows/8137/1 "2023-05-16T19:01:27Z")

</div>

I have CC and CXX set to clang and clang++, however CMAKE is using MSVC instead. I’ve scoured stack overflow and other places and can’t seem to find anyone else running into this problem.

```auto
///c_template on  master ≡  ~2 594ms ⌛ 11:57:46  
❯ echo $CC
clang

///c_template on  master ≡  ~2 11:57:49  
❯ echo $CXX
clang++

///c_template on  master ≡  ~2 156ms ⌛ 11:57:53  
❯ make test
cmake -S . -B build
-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.35.32215.0
-- The CXX compiler identification is MSVC 19.35.32215.0
-- The ASM compiler identification is MSVC
-- Found assembler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done

```

I’ve reproduced the issue in a github action. I’m sure I’ve missed something, but I don’t know what it is.

> <https://github.com/drbartling/c_template/actions/runs/4995308508/jobs/8947013451>

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [May 16, 2023, 11:48pm UTC](https://discourse.cmake.org/t/unable-to-set-compiler-using-windows/8137/2 "2023-05-16T23:48:24Z")

</div>

AFAIK When using the Visual Studio generator, you can only used compilers known by VS, not any command line compiler. They’re selected by `-T`, in your case it should be `-T ClangCL`

Alternatively you can use another generator, like Ninja, with `-G Ninja`.  
Then the environment variables will be considered.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [May 17, 2023, 7:10am UTC](https://discourse.cmake.org/t/unable-to-set-compiler-using-windows/8137/3 "2023-05-17T07:10:52Z")

</div>

see too [Best Practice for Ninja build Visual Studio?](https://discourse.cmake.org/t/best-practice-for-ninja-build-visual-studio/4653)

---

<div class="post-metadata">

### Author: ![rbartling](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/5f8ce5/32.png) [@rbartling](https://discourse.cmake.org/u/rbartling)
#### Post date: [May 18, 2023, 4:40pm UTC](https://discourse.cmake.org/t/unable-to-set-compiler-using-windows/8137/4 "2023-05-18T16:40:31Z")

</div>

Changing the generator worked for building with different compilers. Thanks!

Still running into other issues as I play with CMake on Windows.

> **[GitHub - drbartling/c\_template](https://github.com/drbartling/c_template)**
>
> Contribute to drbartling/c\_template development by creating an account on GitHub.

Maybe I’ll start another thread with a more general topic
