生成的符号名称具有其他前导下划线

时间:2013-04-29 07:07:29

标签: c name-mangling

我在Windows中安装了MinGW编译器。并且有一个项目设置,其中一些第三方*.a文件直接从Linux机器上复制。

尝试编译一个简单的C程序,当我查看*.o文件的符号表时,它有所有符号名称的前导下划线。

示例程序:

int main(int argc, char** argv) 
{   
     int xyz=0; 
     printf("I am Here\n");
}

SymbolTable条目:

Sections:

Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000040  00000000  00000000  0000008c  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000000  2**2
                  ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000000  2**2
                  ALLOC

SYMBOL TABLE:

[  0](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000000 abcd01.c
File
[  2](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x0000000b **_main**
[  3](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text
AUX scnlen 0x3e nreloc 4 nlnno 0
[  5](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .data
AUX scnlen 0x0 nreloc 0 nlnno 0
[  7](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .bss
AUX scnlen 0x0 nreloc 0 nlnno 0
[  9](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 1) 0x00000000 ___main
AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0
[ 11](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __alloca
[ 12](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 **_printf**

RELOCATION RECORDS FOR [.text]:

OFFSET   TYPE              VALUE
00000020 DISP32            __alloca
00000025 DISP32            ___main
00000033 dir32             .text
00000038 DISP32            **_printf**

这里甚至基本C函数都以下划线为前缀。

尝试使用-fno-leading-underscore,但没有用。

MingW版:

$ gcc -v
Reading specs from C:/PROGRA~1/GNUCFO~1//ncbin/../lib/gcc-lib/i386-pc-mks/3.3.1/
specs
Configured with: configure --prefix=/usr/gnu i386-pc-mks --enable-languages=c,c+
+ --disable-nls --disable-shared --enable-sjlj-exceptions --enable-threads --dis
able-win32-registry
Thread model: win32
gcc version 3.3.1 (mingw special 20030804-1)

1 个答案:

答案 0 :(得分:3)

您可能想要尝试使用在Linux下生成的*.a个文件(或其中的*.o个文件)。

这些东西是为Linux环境编译的,你几乎肯定会发现CygWin中的ABI(应用程序二进制接口)是不同的。

CygWin为您提供了类似于Linux的编程环境,因此您可以编译相同的代码。从这个意义上说,它在API(应用程序编程接口)层兼容,不一定是ABI层。

相关问题