交叉构建的COFF文件和MSVS

时间:2017-12-18 12:08:09

标签: c linker static-libraries linker-errors cross-build

我在linux机器上使用i686-w64-mingw32-gcc交叉构建了一个win32静态库。

我在linux端检查了{.1}}生成的.lib文件,并看到:

nm

我还在Windows端检查了bsd_offset.o: U __assert 00000000 T _bsd_offset 00000000 b .bss 00000000 d .data 00000000 i .drectve U _flp3 00000004 C _randNo 00000000 r .rdata 00000000 r .rdata$zzz 00000000 t .text bsdi.o: 00000000 T _bsdi 00000000 b .bss U _clp3 00000000 d .data 00000000 i .drectve 00000004 C _randNo 00000000 r .rdata$zzz 00000000 t .text ... 的.lib文件,并看到:

dumpbin /symbols

一位同事正试图使用​​MSVS2008使用lib构建一个exe,并且看到如下错误:

Microsoft (R) COFF/PE Dumper Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file libLib_rel.lib

File Type: LIBRARY

COFF SYMBOL TABLE
000 00000000 DEBUG  notype       Filename     | .file
    bsd_offset.c
002 00000000 SECT1  notype ()    External     | _bsd_offset
    tag index 00000000 size 00000000 lines 00000000 next function 00000000
004 00000000 SECT1  notype       Static       | .text
    Section length   BF, #relocs    4, #linenums    0, checksum        0
006 00000000 SECT2  notype       Static       | .data
    Section length    0, #relocs    0, #linenums    0, checksum        0
008 00000000 SECT3  notype       Static       | .bss
    Section length    0, #relocs    0, #linenums    0, checksum        0
00A 00000000 SECT4  notype       Static       | .rdata
    Section length   1A, #relocs    0, #linenums    0, checksum        0
00C 00000000 SECT6  notype       Static       | .drectve
    Section length   2C, #relocs    0, #linenums    0, checksum        0
00E 00000000 SECT7  notype       Static       | .rdata$zzz
    Section length   1A, #relocs    0, #linenums    0, checksum        0
010 00000004 UNDEF  notype       External     | _randNo
011 00000000 UNDEF  notype ()    External     | _flp3
012 00000000 UNDEF  notype ()    External     | __assert

String Table Size = 0x35 bytes

COFF SYMBOL TABLE
000 00000000 DEBUG  notype       Filename     | .file
    bsdi.c
002 00000000 SECT1  notype ()    External     | _bsdi
    tag index 00000000 size 00000000 lines 00000000 next function 00000000
004 00000000 SECT1  notype       Static       | .text
    Section length   70, #relocs    1, #linenums    0, checksum        0
006 00000000 SECT2  notype       Static       | .data
    Section length    0, #relocs    0, #linenums    0, checksum        0
008 00000000 SECT3  notype       Static       | .bss
    Section length    0, #relocs    0, #linenums    0, checksum        0
00A 00000000 SECT5  notype       Static       | .drectve
    Section length   26, #relocs    0, #linenums    0, checksum        0
00C 00000000 SECT6  notype       Static       | .rdata$zzz
    Section length   1A, #relocs    0, #linenums    0, checksum        0
00E 00000004 UNDEF  notype       External     | _randNo
00F 00000000 UNDEF  notype ()    External     | _clp3

String Table Size = 0x29 bytes

...

1>------ Build started: Project: StaticLinkExample, Configuration: Release Win32 ------ 1>Linking... 1>testLib_rel.lib(initialise.o) : warning LNK4229: invalid directive '/aligncomm:_randNo,2' encountered; ignored 1>testLib_rel.lib(lib.o) : warning LNK4229: invalid directive '/aligncomm:_randNo,2' encountered; ignored ... 1> Creating library D:\Software\ThirdParty\Lib_v230\Trial\StaticLinkExample\Release\StaticLinkExample.lib and object D:\Software\ThirdPart\Lib_v230\Trial\StaticLinkExample\Release\StaticLinkExample.exp 1>testLib_rel.lib(shared.o) : error LNK2001: unresolved external symbol ___ms_vsnprintf 1>testLib_rel.lib(iniparser.o) : error LNK2001: unresolved external symbol ___ms_vsnprintf 1>testLib_rel.lib(utility.o) : error LNK2001: unresolved external symbol ___ms_vsnprintf 1>testLib_rel.lib(load_glf.o) : error LNK2001: unresolved external symbol ___chkstk_ms 1>testLib_rel.lib(utility.o) : error LNK2001: unresolved external symbol ___chkstk_ms 1>testLib_rel.lib(lib.o) : error LNK2001: unresolved external symbol _fmax 1>testLib_rel.lib(lib.o) : error LNK2001: unresolved external symbol _fmin 1>StaticLinkExample.exp : error LNK2001: unresolved external symbol bsd_offset 1>StaticLinkExample.exp : error LNK2001: unresolved external symbol bsdi nm输出是否合理。如果静态库中存在符号,为什么会出现链接错误。可能是某种方式,交叉构建的lib与MSVS 2008不是二进制兼容的吗?

0 个答案:

没有答案