# CheckIPOSupported not regarded CMAKE\_LINKER\_TYPE

**URL:** https://discourse.cmake.org/t/checkiposupported-not-regarded-cmake-linker-type/13082
**Category:** Usage
**Created:** [November 28, 2024, 1:58am UTC](https://discourse.cmake.org/t/checkiposupported-not-regarded-cmake-linker-type/13082 "2024-11-28T01:58:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gyatpear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gyatpear/32/5159_2.png) [@gyatpear](https://discourse.cmake.org/u/gyatpear)
#### Post date: [November 28, 2024, 1:58am UTC](https://discourse.cmake.org/t/checkiposupported-not-regarded-cmake-linker-type/13082/1 "2024-11-28T01:58:41Z")

</div>

At the present time, GCC LTO cannot link with LLVM LLD, but `CheckIPOSupported` may give different answer depending on how cmake command line invoked.

For

```auto
CC=gcc CXX=g++ LDFLAGS=-fuse-ld=lld cmake

```

`CheckIPOSupported` returns failure, then the project can safely set IPO to OFF.

For

```auto
cmake -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ -D CMAKE_LINKER_TYPE=LLD 

```

`CheckIPOSupported` returns success, then the project may set IPO to ON, then get link-time errors.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [November 28, 2024, 8:36am UTC](https://discourse.cmake.org/t/checkiposupported-not-regarded-cmake-linker-type/13082/2 "2024-11-28T08:36:32Z")

</div>

I failed to reproduce your problem. Can you provide a snippet reproducing the problem?  
By the way, can you specify your environment (platform, compiler type and version, CMake version)?

---

<div class="post-metadata">

### Author: ![gyatpear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gyatpear/32/5159_2.png) [@gyatpear](https://discourse.cmake.org/u/gyatpear)
#### Post date: [November 28, 2024, 8:50am UTC](https://discourse.cmake.org/t/checkiposupported-not-regarded-cmake-linker-type/13082/3 "2024-11-28T08:50:43Z")

</div>

### Environment

Arch Linux  
cmake version 3.31.1  
ninja 1.12.1  
gcc (GCC) 14.2.1 20240910  
LLD 18.1.8 (compatible with GNU linkers)

### Project to Reproduce

`CMakeLists.txt`:

```cmake
cmake_minimum_required(VERSION 3.20)
project(test_proj)
include(CheckIPOSupported)
check_ipo_supported(RESULT C_COMPILER_HAS_IPO_SUPPORT LANGUAGES C)
message(STATUS "LTO: ${C_COMPILER_HAS_IPO_SUPPORT}")
add_executable(main main.c)
set_property(TARGET main PROPERTY INTERPROCEDURAL_OPTIMIZATION ${C_COMPILER_HAS_IPO_SUPPORT})

```

`main.c`:

```c
#include <stdio.h>
int main() {
  printf("Hello world!\n");
  return 0;
}

```

### Command Line Outputs

```output
$ cmake -B build -G Ninja -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ -D CMAKE_LINKER_TYPE=LLD        
-- The C compiler identification is GNU 14.2.1
-- The CXX compiler identification is GNU 14.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - 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: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- LTO: YES
-- Configuring done (1.0s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/tmp.J0m6gKPUMX/build
$ ninja -C build -v                                                                                 
ninja: Entering directory `build'
[1/2] /usr/bin/gcc -flto=auto -fno-fat-lto-objects -MD -MT CMakeFiles/main.dir/main.c.o -MF CMakeFiles/main.dir/main.c.o.d -o CMakeFiles/main.dir/main.c.o -c /tmp/tmp.J0m6gKPUMX/main.c
[2/2] : && /usr/bin/gcc -flto=auto -fno-fat-lto-objects -fuse-ld=lld -Wl,--dependency-file,CMakeFiles/main.dir/link.d CMakeFiles/main.dir/main.c.o -o main && :
FAILED: main 
: && /usr/bin/gcc -flto=auto -fno-fat-lto-objects -fuse-ld=lld -Wl,--dependency-file,CMakeFiles/main.dir/link.d CMakeFiles/main.dir/main.c.o -o main && :
ld.lld: error: undefined symbol: main
>>> referenced by /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../lib/Scrt1.o:(_start)
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

```

### CMakeConfigureLog.yaml

```yaml

---
-
    (Redacted)
-
    kind: "try_compile-v1"
    backtrace:
      - "/usr/share/cmake/Modules/CheckIPOSupported.cmake:138 (try_compile)"
      - "/usr/share/cmake/Modules/CheckIPOSupported.cmake:261 (_ipo_run_language_check)"
      - "CMakeLists.txt:4 (check_ipo_supported)"
    directories:
      source: "/tmp/tmp.J0m6gKPUMX/build/CMakeFiles/_CMakeLTOTest-C/src"
      binary: "/tmp/tmp.J0m6gKPUMX/build/CMakeFiles/_CMakeLTOTest-C/bin"
    buildResult:
      variable: "_IPO_LANGUAGE_CHECK_RESULT"
      cached: true
      stdout: |
        Change Dir: '/tmp/tmp.J0m6gKPUMX/build/CMakeFiles/_CMakeLTOTest-C/bin'
        
        Run Build Command(s): /usr/bin/ninja -v
        [1/4] /usr/bin/gcc -flto=auto -fno-fat-lto-objects -o CMakeFiles/boo.dir/main.c.o -c /tmp/tmp.J0m6gKPUMX/build/CMakeFiles/_CMakeLTOTest-C/src/main.c
        [2/4] /usr/bin/gcc -flto=auto -fno-fat-lto-objects -o CMakeFiles/foo.dir/foo.c.o -c /tmp/tmp.J0m6gKPUMX/build/CMakeFiles/_CMakeLTOTest-C/src/foo.c
        [3/4] : && /usr/bin/cmake -E rm -f libfoo.a && "/usr/bin/gcc-ar" qc libfoo.a CMakeFiles/foo.dir/foo.c.o && "/usr/bin/gcc-ranlib" libfoo.a && :
        [4/4] : && /usr/bin/gcc -flto=auto -fno-fat-lto-objects CMakeFiles/boo.dir/main.c.o -o boo libfoo.a && :
        
      exitCode: 0
...

```

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [November 28, 2024, 9:02am UTC](https://discourse.cmake.org/t/checkiposupported-not-regarded-cmake-linker-type/13082/4 "2024-11-28T09:02:32Z")

</div>

The problem comes from your CMake version specified through `cmake_minumum_required()` command. The policy [CMP0138](https://cmake.org/cmake/help/latest/policy/CMP0138.html) is not defined, so flags are propagated to the IPO check.

Update `cmake_minumum_required()` to version to `3.24` or set explicitly `CMP0138` to `NEW` with [cmake\_policy()](https://cmake.org/cmake/help/latest/command/cmake_policy.html) command.
