How to link to a different libc file?

后端 未结 2 365
故里飘歌
故里飘歌 2020-12-03 18:34

I want to supply the shared libraries along with my program rather than using the target system\'s due to version differences.

ldd says my program uses

相关标签:
2条回答
  • 2020-12-03 19:03

    I found out how to do it:

    rpath specifies where the provided libraries are located. This folder should contain: libc.so.6, libdl.so.2, libgcc_s.so.1 and maybe more. Check with strace to find out which libraries your binary file uses.

    ld.so is the provided linker

    gcc -Xlinker -rpath=/default/path/to/libraries -Xlinker -I/default/path/to/libraries/ld.so program.c

    0 讨论(0)
  • 2020-12-03 19:12

    Passing -nodefaultlibs or -nostdlib to gcc will tell it to not pass the default libraries as arguments to ld. You will then be able to explicitly specify the libc you want to link against. See the gcc(1) man page for more details and caveats regarding both options.

    0 讨论(0)
提交回复
热议问题