# using cmake causing rdynamic in link.txt

**URL:** <https://discourse.cmake.org/t/using-cmake-causing-rdynamic-in-link-txt/15263>\
**Category:** Code\
**Created:** [October 25, 2025, 9:25pm UTC](https://discourse.cmake.org/t/using-cmake-causing-rdynamic-in-link-txt/15263 "2025-10-25T21:25:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggcmk900](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ggcmk900/32/5859_2.png) [@ggcmk900](https://discourse.cmake.org/u/ggcmk900)\
**Post date:** [October 25, 2025, 9:25pm UTC](https://discourse.cmake.org/t/using-cmake-causing-rdynamic-in-link-txt/15263/1 "2025-10-25T21:25:12Z")

</div>

Can someone point out why cmake is introducing -rdynamic in linker file? link.txt.

This is causing nvcc linker to file. I know cmake is causing it because if I dont use cmake (shell script), it does not exhibit this problem…  
**Cmake usage option:**

CMakeLists.:

> set (proj\_name ${CMAKE\_PROJ\_NAME})  
> project (${proj\_name})
> 
> # The version number.
> 
> #set (test\_VERSION\_MAJOR 1)  
> #set (test\_VERSION\_MINOR 0)
> 
> set (CMAKE\_CXX\_FLAGS "  
> -L/usr/lib64  
> -L/usr/lib64/openmpi/lib/  
> -lmpi\_cxx -lnccl -lmpi  
> -I/usr/include/openmpi-x86\_64/  
> -I/usr/local/cuda-12.6/targets/x86\_64-linux/include/ ")
> 
> #set(CMAKE\_CXX\_LINK\_FLAGS “${CMAKE\_CXX\_LINK\_FLAGS} Xlinker --no-export-dynamic”)  
> #set(CMAKE\_CUDA\_FLAGS “${CMAKE\_CUDA\_FLAGS} -Xlinker --no-export-dynamic”)
> 
> set(CMAKE\_CXX\_COMPILER nvcc)  
> include\_directories(“${PROJECT\_BINARY\_DIR}”)  
> add\_executable(${proj\_name} ${proj\_name}.cpp)  
> #target\_link\_options(${proj\_name} PRIVATE “Xlinker --no-export-dynamic”)
> 
> link.txt:

> cat `find . -name link.txt`  
> nvcc -L/usr/lib64 -L/usr/lib64/openmpi/lib/ -lmpi\_cxx -lnccl -lmpi -I/usr/include/openmpi-x86\_64/ -I/usr/local/cuda-12.6/targets/x86\_64-linux/include/ **-rdynamic** “CMakeFiles/ex-1-create-comm.dir/ex-1-create-comm.o” -o ex-1-create-comm
> 
> Shell script w/o using cmake (works):

> set -x  
> FILENAME=ex-1-create-comm  
> EXT=cpp  
> COMPILER=/usr/lib64/openmpi/bin/mpicxx  
> COMPILER=nvcc  
> LOGDIR=log  
> mkdir -p $LOGDIR  
> rm -rf $FILENAME.out  
> $COMPILER  
> -L/usr/lib64 -L/usr/lib64/openmpi/lib/  
> -lmpi\_cxx -lnccl -lmpi -I/usr/include/openmpi-x86\_64/  
> $FILENAME.$EXT -o $FILENAME.out 2\>&1 | tee $LOGDIR/$FILENAME.compile.log
> 
> if [[-f $FILENAME.out]] ; then  
> LD\_LIBRARY\_PATH=/usr/lib64/openmpi/lib/ OMPI\_ALLOW\_RUN\_AS\_ROOT=1 OMPI\_ALLOW\_RUN\_AS\_ROOT\_CONFIRM=1  
> mpirun -np 2 ./$FILENAME.out -allow-run-as-root 2\>&1 | tee $LOGDIR/$FILENAME.run.log  
> fi  
> root@ccs-aus-j08-01:~/extdir/gg/git/codelab/gpu/cuda/nccl/grok#

---

<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:** [October 26, 2025, 9:22am UTC](https://discourse.cmake.org/t/using-cmake-causing-rdynamic-in-link-txt/15263/2 "2025-10-26T09:22:54Z")

</div>

The definition of the compiler (i.e. setting the variable `CMAKE_CXX_COMPILER`) must be done **before** the `project()` command.
