如何在Mac终端中查看C++功能的损坏名称

How to see mangled name of C++ function in Mac Terminal

本文关键字:功能 C++ 损坏 Mac 终端      更新时间:2023-10-16

我想看看这段代码的损坏名称。我应该怎么做。

我已经通过使用 G++ 编译器编译代码并看到输出为 ./a.out 但未打印任何内容来尝试这一点。我已经在窗口中读过有关dumpbin.exe但对Mac一无所知。

名芒.cpp

// This demonstrate the nameMangling of function to make their signature.
int square(int x){
    return x*x;
}
double square(double y){
    return y*y;
}
void nothing1(int a, float b, char c, int &d){
}
void nothing2(char a, int b, float &c, double &d){
}
int main(){
    return 0; // Indicate successful termination
}

预期结果是

__Z6squarei
__Z6squared
__Z8nothing1ifcRi
__Z8nothing2ciRfRd_主要

对我的问题的任何了解将不胜感激。谢谢

如果您没有安装binutils,请安装该软件包。这可能是一个不错的起点:在Mac OSX上安装binutils

然后nm a.out应该向你显示损坏的名称,nm -C a.out应该向您展示被破坏的名称。