C++ 的 64 位名称修改 [英] 64bit name mangling for c++

查看:26
本文介绍了C++ 的 64 位名称修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,其中包含以下行

I have a bit of code which has the following line

  #pragma comment(linker, "/include:_test@12") 

当我使用配置类型为 32 位的 C++ Visual Studio 2010 编译代码时,使用此代码的项目工作正常(我也在 32 位 Windows 机器上).

The project which uses this code works fine when I compile the code using C++ Visual Studio 2010 with configuration type 32bit (I am also on a 32 bit windows machine).

当我将机器更改为 64 位并使用使用 C++ Visual Studio 2010 编译的 x64 配置时出现链接错误.

I get a link error when I change the machine to 64bit and use x64 configuration which compiling with C++ Visual Studio 2010.

32 位和 64 位的 C++ 名称修改是否不同?如果是这样,我在哪里可以找到 64 位 C++ 名称修改约定?

Is C++ name mangling different for 32bit vs 64bit? If so, where can I find the 64bit C++ name mangling conventions?

推荐答案

是的,名称修改在 32 位和 64 位之间是不同的.一篇涵盖确切格式的合理文章可以在此处找到.但是,您可以通过简单地编译到两个目标并检查生成的映射文件来很快地分辨出主要差异.根据我的经验,它们几乎相同(64 位添加了一个小数据,可能会改变其他数据).

Yes the name mangling is different between 32 and 64 bit. A reasonable article covering the exact formats can be found here. You can tell the major differences pretty quickly, however, by simply compiling to both targets and examining the resulting map files. From my experience they're almost identical (64bit adds a small datum, potentially changes others).

简单示例:void foo();

32bit: ?foo@A@@QAEXXZ
64bit: ?foo@A@@QEAAXXZ

对于非重整的 std 调用,长度后缀可能会有很大不同,具体取决于参数堆栈的使用情况.VC++ 的默认 64 位设置不添加下划线,也不编码长度后缀.以下是使用纯开箱即用设置编译的 32/64 位配置:

For non-mangled std call, the length suffix can be substantially different, depending on the parameter stack usage. The default 64-bit settings for VC++ do not prepend underscores nor does it encode length-suffixes. The following was compiled both 32/64bit configs with pure out-of-the-box settings:

extern "C" int _stdcall func2(int, int, char*);

32bit: _func2@12
64bit: func2

没什么意义,是吗.

完成电路,未损坏的_cdecl,这样做:

Completing the circuit, unmangled _cdecl, which does this:

extern "C" int _cdecl func2(int, int, char*);

32bit: _func2
64bit: func2

如果他们似乎特意让你知道你正在拉入或导出什么,证据表明你可能是正确的.

If it seems like they went out of their way to make you know what you're pulling-in or exporting-out, evidence suggests you're probably correct.

这篇关于C++ 的 64 位名称修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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