简体   繁体   English

C++ 的 64 位名称修改

[英]64bit name mangling for c++

I have a bit of code which has the following line我有一些代码,其中包含以下行

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

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

I get a link error when I change the machine to 64bit and use x64 configuration which compiling with C++ Visual Studio 2010.当我将机器更改为 64 位并使用使用 C++ Visual Studio 2010 编译的 x64 配置时出现链接错误。

Is C++ name mangling different for 32bit vs 64bit? 32 位和 64 位的 C++ 名称重整不同吗? If so, where can I find the 64bit C++ name mangling conventions?如果是这样,我在哪里可以找到 64 位 C++ 名称修改约定?

Yes the name mangling is different between 32 and 64 bit.是的,名称修改在 32 位和 64 位之间是不同的。 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).根据我的经验,它们几乎相同(64 位添加了一个小数据,可能会更改其他数据)。

Simple sample: void foo();简单示例: void foo();

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

For non-mangled std call, the length suffix can be substantially different, depending on the parameter stack usage.对于非重整的 std 调用,长度后缀可能会有很大不同,具体取决于参数堆栈的使用情况。 The default 64-bit settings for VC++ do not prepend underscores nor does it encode length-suffixes. VC++ 的默认 64 位设置不添加下划线,也不编码长度后缀。 The following was compiled both 32/64bit configs with pure out-of-the-box settings:以下是使用纯开箱即用设置编译的 32/64 位配置:

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

32bit: _func2@12
64bit: func2

Not much point there, is there.没有多大意义,是有。

Completing the circuit, unmangled _cdecl, which does this:完成电路,unmangled _cdecl,它这样做:

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.如果看起来他们竭尽全力让你知道你正在拉入或导出什么,证据表明你可能是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM