Is there a .def file equivalent on Linux for controlling exported function names in a shared library?

后端 未结 4 856
独厮守ぢ
独厮守ぢ 2021-01-31 12:04

I am building a shared library on Ubuntu 9.10. I want to export only a subset of my functions from the library. On the Windows platform, this would be done using a module defini

4条回答
  •  野性不改
    2021-01-31 12:16

    The most common way to only make certain symbols visible in a shared object on linux is to pass the -fvisibility=hidden to gcc and then decorate the symbols that you want to be visible with __attribute__((visibility("default"))).

    If your looking for an export file like solution you might want to look at the linker option --retain-symbols-file=FILENAME which may do what you are looking for.

    I don't know an easy way of exporting a function with a different name from its function name, but it is probably possible with an elf editor. Edit: I think you can use a linker script (have a look at the man page for ld) to assign values to symbols in the link step, hence giving an alternative name to a given function. Note, I haven't ever actually tried this.

    To view the visible symbols in a shared object you can use the readelf command. readelf -Ds if I remember correctly.

提交回复
热议问题