C ++的64位名称处理 [英] 64bit name mangling for c++

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

问题描述

我有一些下面的代码行

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

当我使用C ++ Visual Studio 2010编译代码时,使用此代码的项目运行良好配置类型为32位(我也是在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位并使用x64配置时,会出现链接错误C ++ Visual Studio2010。

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, buy 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天全站免登陆