# Cmake not detecting the CXX compiler

**URL:** https://discourse.cmake.org/t/cmake-not-detecting-the-cxx-compiler/190
**Category:** Usage
**Tags:** os:linux
**Created:** [November 13, 2019, 11:50am UTC](https://discourse.cmake.org/t/cmake-not-detecting-the-cxx-compiler/190 "2019-11-13T11:50:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rmadhuraj](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rmadhuraj/32/162_2.png) [@rmadhuraj](https://discourse.cmake.org/u/rmadhuraj)
#### Post date: [November 13, 2019, 11:50am UTC](https://discourse.cmake.org/t/cmake-not-detecting-the-cxx-compiler/190/1 "2019-11-13T11:50:21Z")

</div>

HI

My Cmake by default not taking the CXX compiler, taking only C for the compilation. So the cpp files in the project were not being compiled.

My tool chain file is like this

> set(CMAKE\_SYSTEM\_PROCESSOR aarch64)
> 
> # Toolchain settings
> 
> set(CMAKE\_C\_COMPILER aarch64-linux-gnu-gcc)  
> set(CMAKE\_CXX\_COMPILER aarch64-linux-gnu-g++)  
> set(AS aarch64-linux-gnu-as)  
> set(AR aarch64-linux-gnu-ar)  
> set(OBJCOPY aarch64-linux-gnu-objcopy)  
> set(OBJDUMP aarch64-linux-gnu-objdump)  
> set(SIZE aarch64-linux-gnu-size)
> 
> set(CMAKE\_C\_FLAGS “-D\_GNU\_SOURCE -D\_POSIX\_C\_SOURCE=200809 -std=gnu11 -fms-extensions -fdata-sections -ffunction-sections -Wno-missing-declarations” CACHE INTERNAL “c compiler flags”)  
> set(CMAKE\_CXX\_FLAGS “-D\_GNU\_SOURCE -D\_POSIX\_C\_SOURCE=200809 -std=gnu++11 -fms-extensions -fdata-sections -ffunction-sections” CACHE INTERNAL “cxx compiler flags”)  
> set(CMAKE\_ASM\_FLAGS “” CACHE INTERNAL “asm compiler flags”)  
> if (APPLE)  
> set(CMAKE\_EXE\_LINKER\_FLAGS “-lrt -dead\_strip” CACHE INTERNAL “exe link flags”)  
> else (APPLE)  
> set(CMAKE\_EXE\_LINKER\_FLAGS “-lrt -Wl,–gc-sections” CACHE INTERNAL “exe link flags”)  
> endif (APPLE)
> 
> SET(CMAKE\_C\_FLAGS\_DEBUG “-O0 -g -ggdb3” CACHE INTERNAL “c debug compiler flags”)  
> SET(CMAKE\_CXX\_FLAGS\_DEBUG “-O0 -g -ggdb3” CACHE INTERNAL “cxx debug compiler flags”)  
> SET(CMAKE\_ASM\_FLAGS\_DEBUG “-g -ggdb3” CACHE INTERNAL “asm debug compiler flags”)
> 
> SET(CMAKE\_C\_FLAGS\_RELEASE “-O2 -g -ggdb3” CACHE INTERNAL “c release compiler flags”)  
> SET(CMAKE\_CXX\_FLAGS\_RELEASE “-O2 -g -ggdb3” CACHE INTERNAL “cxx release compiler flags”)  
> SET(CMAKE\_ASM\_FLAGS\_RELEASE “” CACHE INTERNAL “asm release compiler flags”)

When do a cmake configure , i observed only C compiler is detection but the cmake not trying to include the CXX compiler like this

> mkdir build\_generic  
> cd build\_generic && cmake -G"Unix Makefiles"   
> -DCMAKE\_BUILD\_TYPE=Debug -DVERSION=1.3.1 -DGIT\_SHORT\_HASH=bf8667f   
> -DCMAKE\_TOOLCHAIN\_FILE=…/toolchain/arm64.cmake …  
> – The C compiler identification is GNU 4.8.4  
> – Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc  
> – Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc – works  
> – Detecting C compiler ABI info  
> – Detecting C compiler ABI info - done  
> – Detecting C compile features  
> – Detecting C compile features - done  
> – Configuring done  
> – Generating done  
> – Build files have been written to: /home/madhu.r/ssow3/ssow5/uwb-apps/repos/decawave-uwb-core/build\_generic

Please help me in resolving this.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [November 13, 2019, 2:04pm UTC](https://discourse.cmake.org/t/cmake-not-detecting-the-cxx-compiler/190/2 "2019-11-13T14:04:40Z")

</div>

The project’s `CMakeLists.txt` file needs to specify that the `CXX` language should be enabled. I suspect that it is enabling only `C`. For example, it may contain something like

```cmake
cmake_minimum_required(VERSION 3.10)
project(MyProject C)

```

That `C` option to `project()` says to only enable that one language.

Or it may be doing something like

```cmake
cmake_minimum_required(VERSION 3.10)
project(MyProject NONE)
enable_language(C)

```

which is essentially equivalent.

Maybe the project has some options to enable C++ parts.

---

<div class="post-metadata">

### Author: ![rmadhuraj](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rmadhuraj/32/162_2.png) [@rmadhuraj](https://discourse.cmake.org/u/rmadhuraj)
#### Post date: [November 14, 2019, 4:26am UTC](https://discourse.cmake.org/t/cmake-not-detecting-the-cxx-compiler/190/3 "2019-11-14T04:26:35Z")

</div>

Thanks Brad,

That quickly helped me to figure the issue.

It is written

> project(myproject VERSION ${VERSION} LANGUAGES C )

in my CMakeListx.txt

So i changed it to

> project(myproject VERSION ${VERSION} LANGUAGES C CXX)

And that invoked CXX to the build environment.

Thanks again.
