0

I am using cmake to compile a big project and want the resulted ELF file to use my customized ld.so instead of the system default one. To be more specific, in the resulted elf file, i want the "Requesting program interpreter: /lib64/ld-linux-x86-64.so.2" to become "Requesting program interpreter: /path/to/my/ld.so".

I need to do this in the compilation stage, but cannot figure out the right way to specify the corresponding FLAGS to CXX. The only information I have is that the equivalent thing in gcc is LDFALGS="-Wl,--dynamic-linker=/path/to/custumized/ld.so". I am new to c++ and cmake, can somebody save me?

HH Jiaqi
  • 9
  • 2
  • So you want to add a **linker flag** in CMake project. Have you checked other questions on that topic? E.g. [that one](https://stackoverflow.com/questions/11783932/how-do-i-add-a-linker-or-compile-flag-in-a-cmake-file). – Tsyvarev Jul 31 '21 at 18:21
  • Hi, Tsyvarev. The problem is solved. I first tried to set linker flag using CMAKE_EXE_LINKER_FLAGS, but somehow the build failed at the compilation stage. Then I got the idea that "target_link_libraries" can be used to indicate not only dependent libraries but also linker flags, so I used target_link_libraries to add a linker flag "-Wl,-dynamic-linker,/path/to/my/ld.so", it succeed. This is consistent with vitaut's answer in your suggested link. Thanks! – HH Jiaqi Aug 02 '21 at 03:34

0 Answers0