# Swapping project to xlc 17.1.1 with mixed C / C++ code

**URL:** https://discourse.cmake.org/t/swapping-project-to-xlc-17-1-1-with-mixed-c-c-code/8589
**Category:** Usage
**Tags:** os:aix
**Created:** [July 24, 2023, 10:17am UTC](https://discourse.cmake.org/t/swapping-project-to-xlc-17-1-1-with-mixed-c-c-code/8589 "2023-07-24T10:17:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tmx1835](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/43a26b/32.png) [@tmx1835](https://discourse.cmake.org/u/tmx1835)
#### Post date: [July 24, 2023, 10:17am UTC](https://discourse.cmake.org/t/swapping-project-to-xlc-17-1-1-with-mixed-c-c-code/8589/1 "2023-07-24T10:17:08Z")

</div>

We’ve been using cmake for a couple of months on AIX 7.2 with XLC 16, we need to swap to the clang based xlc 17.1.1 however have hit a bit of an issue as our app is a mix of c and c++ when we compile our c source with the ibm-clang++\_r compiler.

i can demonstrate the problem with a hello.c and the CC / CXX environment variables set to /opt/IBM/openxlC/17.1.1/bin/ibm-clang++\_r (see below).

We’re using CMake 3.26.3 .

hello.c

```auto
#include <stdio.h>

int main(int argc, char **argv) {
  printf("hello world\n");
}

```

CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.23)

project(hello LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 11)

add_compile_options (-q64 -qrtti -qchars=signed -+)
add_link_options (-brtl -qrtti -q64 -qarch=pwr8 -qtune=pwr9)

set_source_files_properties(hello.c PROPERTIES LANGUAGE CXX)

add_executable(hello hello.c)

```

output of cmake .

```auto
-bash-5.1$ cmake .
-- The C compiler identification is unknown
-- The CXX compiler identification is IBMClang 17.1.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/IBM/openxlC/17.1.1/bin/ibm-clang++_r
-- Check for working C compiler: /opt/IBM/openxlC/17.1.1/bin/ibm-clang++_r - broken
CMake Error at /opt/cmake/cmake-3.26.3-xlc/share/cmake-3.26/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/opt/IBM/openxlC/17.1.1/bin/ibm-clang++_r"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /data/js/cpptest/CMakeFiles/CMakeScratch/TryCompile-7Flaeb

    Run Build Command(s):/opt/cmake/cmake-3.26.3-xlc/bin/cmake -E env VERBOSE=1 /usr/local/bin/gmake -f Makefile cmTC_78528/fast && /usr/local/bin/gmake -f CMakeFiles/cmTC_78528.dir/build.make CMakeFiles/cmTC_78528.dir/build
    gmake[1]: Entering directory '/data/js/cpptest/CMakeFiles/CMakeScratch/TryCompile-7Flaeb'
    Building C object CMakeFiles/cmTC_78528.dir/testCCompiler.c.o
    /opt/IBM/openxlC/17.1.1/bin/ibm-clang++_r -o CMakeFiles/cmTC_78528.dir/testCCompiler.c.o -c /data/js/cpptest/CMakeFiles/CMakeScratch/TryCompile-7Flaeb/testCCompiler.c
    .ibm-clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
    /data/js/cpptest/CMakeFiles/CMakeScratch/TryCompile-7Flaeb/testCCompiler.c:2:3: error: "The CMAKE_C_COMPILER is set to a C++ compiler"
    # error "The CMAKE_C_COMPILER is set to a C++ compiler"
      ^
    1 error generated.
    CMakeFiles/cmTC_78528.dir/build.make:77: recipe for target 'CMakeFiles/cmTC_78528.dir/testCCompiler.c.o' failed
    gmake[1]: *** [CMakeFiles/cmTC_78528.dir/testCCompiler.c.o] Error 1
    gmake[1]: Leaving directory '/data/js/cpptest/CMakeFiles/CMakeScratch/TryCompile-7Flaeb'
    Makefile:127: recipe for target 'cmTC_78528/fast' failed
    gmake: *** [cmTC_78528/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)

-- Configuring incomplete, errors occurred!

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 24, 2023, 10:54am UTC](https://discourse.cmake.org/t/swapping-project-to-xlc-17-1-1-with-mixed-c-c-code/8589/2 "2023-07-24T10:54:15Z")

</div>

I don’t think you should try to use the C++ compiler _as_ the C compiler to do what you want. Instead, you should set the `LANGUAGE` source file property on the C sources to use the C++ compiler (if I understand what your goal is here at least).

---

<div class="post-metadata">

### Author: ![tmx1835](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/43a26b/32.png) [@tmx1835](https://discourse.cmake.org/u/tmx1835)
#### Post date: [July 24, 2023, 11:43am UTC](https://discourse.cmake.org/t/swapping-project-to-xlc-17-1-1-with-mixed-c-c-code/8589/3 "2023-07-24T11:43:28Z")

</div>

Yep - i did, that, in my test hello project i updated the CMakeLists.txt to set LANGUAGES to CXX

i also set

`set_source_files_properties(hello.c PROPERTIES LANGUAGE CXX)`

so i thought it would compile with the CXX compiler.

This technique works fine on linux with GCC/G++.

so bit perplexed. its almost as the warning generated by the C compile check is being subsequently treated as an error. (but i am only speculating)

---

<div class="post-metadata">

### Author: ![tmx1835](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/43a26b/32.png) [@tmx1835](https://discourse.cmake.org/u/tmx1835)
#### Post date: [July 24, 2023, 11:47am UTC](https://discourse.cmake.org/t/swapping-project-to-xlc-17-1-1-with-mixed-c-c-code/8589/4 "2023-07-24T11:47:06Z")

</div>

ignore me - i am being dense… i may have it sorted

---

<div class="post-metadata">

### Author: ![tmx1835](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/43a26b/32.png) [@tmx1835](https://discourse.cmake.org/u/tmx1835)
#### Post date: [July 24, 2023, 12:00pm UTC](https://discourse.cmake.org/t/swapping-project-to-xlc-17-1-1-with-mixed-c-c-code/8589/5 "2023-07-24T12:00:44Z")

</div>

File save error, this does indeed address my issue. It appears in our main project a number of CMakeLists.txt files still had LANGUAGES set to C and CXX.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 24, 2023, 12:51pm UTC](https://discourse.cmake.org/t/swapping-project-to-xlc-17-1-1-with-mixed-c-c-code/8589/6 "2023-07-24T12:51:21Z")

</div>

> [@tmx1835](#):
>
> so bit perplexed. its almost as the warning generated by the C compile check is being subsequently treated as an error. (but i am only speculating)

The error comes from [this code](https://gitlab.kitware.com/cmake/cmake/-/blob/6194193a8a0a476539590aabbb27094d1aff136a/Modules/CMakeTestCCompiler.cmake#L42-44) which errors if the C compiler sets `__cplusplus`.
