Renaming symbols at compile time without changing the code in a cross platform way

白昼怎懂夜的黑 提交于 2019-12-23 09:18:13

问题


In creating a static object is it possible to rename the symbols at compile time (without changing the code) in a cross platform way? I have recently had objcopy recommended, but linux is not the only target platform it must also work on a mac. I am compiling using gcc, so I was hoping that there was a gcc option of some sort.

I have heard about .def files, but this may have been misleading as the information about them that I have found seems to be for windows.

Edit: I'm trying to change the name of C and Fortran functions, specifically pre-pending them with the word "wrap" in order to avoid symbol conflicts at link time.


回答1:


is it possible to rename the symbols at compile time

You might be able to achieve it with preprocessor:

gcc -c foo.c -Dfoo=foo_renamed



回答2:


You can use the gcc alias attribute to make multiple symbols that point to the same function.

void name1() __attribute__((alias ("name2")));

I'm not sure if the alias attribute works for other types of symbols (e.g. variables).



来源:https://stackoverflow.com/questions/7204836/renaming-symbols-at-compile-time-without-changing-the-code-in-a-cross-platform-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!