# \`-static-pie\` is incompatible with \`CheckPIESupported\`

**URL:** https://discourse.cmake.org/t/static-pie-is-incompatible-with-checkpiesupported/13696
**Category:** Usage
**Created:** [March 7, 2025, 5:14pm UTC](https://discourse.cmake.org/t/static-pie-is-incompatible-with-checkpiesupported/13696 "2025-03-07T17:14:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![hebasto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hebasto/32/4713_2.png) [@hebasto](https://discourse.cmake.org/u/hebasto)
#### Post date: [March 7, 2025, 5:14pm UTC](https://discourse.cmake.org/t/static-pie-is-incompatible-with-checkpiesupported/13696/1 "2025-03-07T17:14:47Z")

</div>

```auto
$ cat CMakeLists.txt 
cmake_minimum_required(VERSION 3.30)
project(TestStaticPIE LANGUAGES CXX)

include(CheckPIESupported)
check_pie_supported(OUTPUT_VARIABLE output LANGUAGES CXX)
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
add_executable(test main.cpp)

```

```auto
$ cat main.cpp 
#include <iostream>

int main() {
  std::cout << "Test.\n";
}

```

After running

```auto
$ LDFLAGS="-static-pie" cmake -B build
$ cmake --build build

```

the resulting executable is _not_ linked statically.

---

<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: [March 7, 2025, 6:21pm UTC](https://discourse.cmake.org/t/static-pie-is-incompatible-with-checkpiesupported/13696/2 "2025-03-07T18:21:29Z")

</div>

The support of `PIE` is done through dedicated CMake private variables which are used if the `check_pie_supported()` command is successful. So, it is not required nor recommended specifying directly PIE options.

Now, the possibility to link statically is not part of the current mechanism. So the link command will have both `PIE` link options `-pie` and `-static-pie` and I suspect that `-pie` option override the `-static-pie` one.

Please open an [issue](https://gitlab.kitware.com/cmake/cmake/-/issues/) to document this current limitation.

---

<div class="post-metadata">

### Author: ![hebasto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hebasto/32/4713_2.png) [@hebasto](https://discourse.cmake.org/u/hebasto)
#### Post date: [March 10, 2025, 6:26pm UTC](https://discourse.cmake.org/t/static-pie-is-incompatible-with-checkpiesupported/13696/3 "2025-03-10T18:26:22Z")

</div>

[https://gitlab.kitware.com/cmake/cmake/-/issues/26757](https://gitlab.kitware.com/cmake/cmake/-/issues/26757)
