Cmake not detecting the CXX compiler

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.

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_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_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.

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.