# Add prefix right before "-Wl,rpath,PATH"

**URL:** https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382
**Category:** Usage
**Tags:** os:linux
**Created:** [March 16, 2024, 6:08pm UTC](https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382 "2024-03-16T18:08:37Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Danesh\_Daroui](https://discourse.cmake.org/user_avatar/discourse.cmake.org/danesh_daroui/32/4407_2.png) [@Danesh\_Daroui](https://discourse.cmake.org/u/Danesh_Daroui)
#### Post date: [March 16, 2024, 6:08pm UTC](https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382/1 "2024-03-16T18:08:37Z")

</div>

Hi all,  
I have a cmake script which works fine with both GNU and Intel compilers. Now I intend to compile my code with nvcc to generate CUDA compatible code and surprisingly nvcc compiler font-end does not understand “-Wl,rpath,PATH” which is added by cmake to the link libraries. I have tried and I see that when I add “-Xcompiler” right before this to become “-Xcompiler -Wl,rpath,PATH” then nvcc links the project correctly. Does anybody know how can I enhance my cmake script, so cmake will generate Makefile that automatically added “-Xcompiler” right before “-Wl,rpath,PATH”?  
Regards,  
Dan

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [March 16, 2024, 8:37pm UTC](https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382/2 "2024-03-16T20:37:49Z")

</div>

@robert.maynard Do you know if the behavior Danesh describes is expected?

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [March 18, 2024, 8:22am UTC](https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382/3 "2024-03-18T08:22:53Z")

</div>

What version of nvcc and CMake are you using?

nvcc 10.2+ with CMake 3.17+ will automatically pass the `-forward-unknown-to-host-compiler` flag when compiling or linking with nvcc. That will allow automatic propagation of flags like `-Wl,rpath` to the host compiler.

---

<div class="post-metadata">

### Author: ![Danesh\_Daroui](https://discourse.cmake.org/user_avatar/discourse.cmake.org/danesh_daroui/32/4407_2.png) [@Danesh\_Daroui](https://discourse.cmake.org/u/Danesh_Daroui)
#### Post date: [March 19, 2024, 5:26pm UTC](https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382/4 "2024-03-19T17:26:44Z")

</div>

Hi Rob and Craig,  
Thanks for your answers. I am using nvcc 12.4.99 and cmake 3.27.7. My intention is to just add -Xcompiler as a prefix to -Wl,rpath because when I do manually the code links correctly. Or, the other alternative is to setup cmake not to add -Wl,rpath it also works. Can you please advice?  
Regards,  
Dan

---

<div class="post-metadata">

### Author: ![Danesh\_Daroui](https://discourse.cmake.org/user_avatar/discourse.cmake.org/danesh_daroui/32/4407_2.png) [@Danesh\_Daroui](https://discourse.cmake.org/u/Danesh_Daroui)
#### Post date: [March 30, 2024, 10:01am UTC](https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382/5 "2024-03-30T10:01:16Z")

</div>

@robert.maynard, @craig.scott  
May I ask my question like this? Is there anyway to configure CMake script so no “-Wl,rpath, PATH” will be added in the linking command at all? Then it will solve my problem. Now I have to do it manually and things work without problem.  
Regards,  
Danesh

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [March 30, 2024, 10:32am UTC](https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382/6 "2024-03-30T10:32:06Z")

</div>

Does [CMAKE\_SKIP\_RPATH](https://cmake.org/cmake/help/latest/variable/CMAKE_SKIP_RPATH.html) give you what you are looking for?

---

<div class="post-metadata">

### Author: ![Danesh\_Daroui](https://discourse.cmake.org/user_avatar/discourse.cmake.org/danesh_daroui/32/4407_2.png) [@Danesh\_Daroui](https://discourse.cmake.org/u/Danesh_Daroui)
#### Post date: [March 30, 2024, 10:43am UTC](https://discourse.cmake.org/t/add-prefix-right-before-wl-rpath-path/10382/7 "2024-03-30T10:43:33Z")

</div>

Oh yes that did the job! I added this line in my cmake script and no rpath is now added:

set(CMAKE\_SKIP\_RPATH TRUE)

Thanks a lot @craig.scott.
