c++ - 如何为 C++ 函数定义属性别名?

标签 c++ linux gcc compiler-errors

在我的 cpp 文件中,我有以下内容:

int A()
{
}
void B_A() __attribute__((alias ("A")));

我收到错误: B_A() 别名为 undefined symbol A; 但是,正如您所注意到的,A 是在此之前定义的。

所以有什么问题!?

最佳答案

来自 the docs :

In C++, the mangled name for the target must be used.

所以,您需要 A 的错位名称,或者您需要给 A C 链接,这样它的名字就不会首先被错位。

关于c++ - 如何为 C++ 函数定义属性别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7100919/

相关文章:

c - 在 LINUX 中创建共享库会抛出错误

c - 错误: expected primary-expression before "__attribute__"

c++ - C++ 中的 register 关键字有什么问题?

c++ - cufftPlan2d 异常

c++ - 如何在Linux下用C++获取缓冲/缓存内存大小?

mysql - Grep 连接表 MySQL/Linux

c - 让 gcc 警告隐式转换

c++ - 如何将类方法转换为 QScriptEngine::FunctionSignature

c++ - 返回后的结构成员地址

加密 API 与手动实现的算法