在编译时重命名符号而不用跨平台方式更改代码 [英] Renaming symbols at compile time without changing the code in a cross platform way

查看:186
本文介绍了在编译时重命名符号而不用跨平台方式更改代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建一个静态对象时,是否可以在编译时重新命名这些符号(而不需要改变代码)?我最近推荐了objcopy,但是linux并不是唯一的目标平台,它也必须在mac上工作。我正在编译使用gcc,所以我希望有某种类型的gcc选项。

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.

我听说过.def文件,但这可能是误导性的我发现它们的信息似乎是windows。

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.

编辑:
我试图改变C和Fortran函数的名称,特别是为了避免链接时出现符号冲突,预先将它们与单词wrap一起预先处理。

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.

推荐答案


是否可以在编译时重新命名符号

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

这篇关于在编译时重命名符号而不用跨平台方式更改代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆