# How prevent undecorated -fPIC when building w/ hipcc + NVIDIA?

**URL:** https://discourse.cmake.org/t/how-prevent-undecorated-fpic-when-building-w-hipcc-nvidia/14104
**Category:** Code
**Created:** [May 15, 2025, 11:03pm UTC](https://discourse.cmake.org/t/how-prevent-undecorated-fpic-when-building-w-hipcc-nvidia/14104 "2025-05-15T23:03:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![derobins](https://discourse.cmake.org/user_avatar/discourse.cmake.org/derobins/32/5568_2.png) [@derobins](https://discourse.cmake.org/u/derobins)
#### Post date: [May 15, 2025, 11:03pm UTC](https://discourse.cmake.org/t/how-prevent-undecorated-fpic-when-building-w-hipcc-nvidia/14104/1 "2025-05-15T23:03:30Z")

</div>

I’m building a C++ library with hipcc that can have either an amd or nvidia back-end depending on the HIP\_PLATFORM setting. I’m building both static and shared libraries via building an object library that gets linked into the static/shared libraries to avoid the double compile. Everything works fine for AMD, but when building for NVIDIA, there is CMake magic happening that is trying to add -fPIC to the shared library target under the hood, which makes nvcc sad (the object library is built with -Xcompile=-fPIC, so no problems there). This library is only using C++ with .cpp/.h file extensions, btw. No CUDA kernels or .cu files at this time.

I’m not globally setting POSITION\_INDEPENDENT\_CODE and that property is explicitly set to OFF for the shared library target (in lieu of me manually setting it, since CMake is guessing incorrectly). The only place where I see -fPIC added to flags is CMAKE\_SHARED\_LINKER\_FLAGS\_INIT. I’ve tried making this a blank string, but that doesn’t help.

How can I either (a) convince CMake to stop adding -fPIC for the shared library target or (b) get CMake to understand that hipcc is driving nvcc so -fPIC needs to be decorated with -Xcompiler, etc.? Is there something I might be missing?

I’m on Linux, btw, with software versions as follows:

CMake: 3.23.2  
g++: 9.4.0  
nvcc: 12.8  
hipcc: 6.1 (clang 17.0.0)

Thanks!

---

<div class="post-metadata">

### Author: ![derobins](https://discourse.cmake.org/user_avatar/discourse.cmake.org/derobins/32/5568_2.png) [@derobins](https://discourse.cmake.org/u/derobins)
#### Post date: [May 17, 2025, 5:57pm UTC](https://discourse.cmake.org/t/how-prevent-undecorated-fpic-when-building-w-hipcc-nvidia/14104/2 "2025-05-17T17:57:37Z")

</div>

I finally answered my own question: You can use `-forward-unknown-to-host-compiler` to send everything nvcc doesn’t know about to gcc/clang/whatever.
