How can I get gcc to add a prefix to all symbol names

前端 未结 2 1319
悲&欢浪女
悲&欢浪女 2020-12-16 00:54

I know that in the past there was an option -fprefix-function-name that would add a prefix to all generated symbols, it doesn\'t seem to be part of gcc anymore.

相关标签:
2条回答
  • 2020-12-16 01:33

    *EDIT: George Skoptsov's solution's better than mine :) The nm trick might come in handy though.


    This is not exactly what you are looking for, but I have had to do something similar in the past (renaming the symbols exported by a library)

    If you know the names of the symbols you want to redefine you can try using objcopy --redefine-syms old=new . See the man pages of objcopy for more details on the input (objcopy might overwrite your file so be careful with that)

    If you do not know the names of the symbols you can trying using nm to get a list of symbols. Again, since I am not sure what kind of symbols you are looking for, the man pages will probably be your best bet.

    0 讨论(0)
  • 2020-12-16 01:35

    I believe this answer will give you the solution.

    In short, you can 'prefix' symbols in an existing library using objcopy like this:

    objcopy --prefix-symbols=foo_ foo.o

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