依赖VS2010中静态编译的库时未定义的符号

Undefined symbols when depending on a statically compiled library from VS2010

本文关键字:未定义 符号 编译 VS2010 静态 依赖      更新时间:2023-10-16

我在Visual Stuio 2012学习版中有一个项目,我想包括一个静态库,用gccMinGW编译。我把图书馆包括在项目的选项中。

不工作。接下来,我尝试了一个最小库的模型。

test.c

int foo(){return 5;}

cmd:

gcc -c test.c
ar rcs libtest.a test.o

objdump:

C:ARM_Workpsace - LegacyHardwareEmulationbuild>objdump -t test.o
test.o:     file format pe-i386
SYMBOL TABLE:
[  0](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000000 test.c
File
[  2](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 1) 0x00000000 _testfun2
AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0
[  4](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text
AUX scnlen 0xa nreloc 0 nlnno 0
[  6](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .data
AUX scnlen 0x0 nreloc 0 nlnno 0
[  8](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .bss
AUX scnlen 0x0 nreloc 0 nlnno 0
[ 10](sec  4)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .rdata$zzz
AUX scnlen 0x11 nreloc 0 nlnno 0
[ 12](sec  5)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .eh_frame
AUX scnlen 0x38 nreloc 1 nlnno 0

但VS2010仍然返回相同的错误:

1>------ Rebuild All started: Project: ReverbTwo, Configuration: Debug Win32 ------
1>  ReverbTwo.cpp
1>  RackAFXDLL.cpp
1>  pluginobjects.cpp
1>  plugin.cpp
1>  Generating Code...
1>plugin.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>     Creating library C:UsersuserAppDataRoamingRackAFXPlugInsReverbTwo.lib and object C:UsersuserAppDataRoamingRackAFXPlugInsReverbTwo.exp
1>ReverbTwo.obj : error LNK2019: unresolved external symbol "int __cdecl testfun2(void)" (?testfun2@@YAHXZ) referenced in function "public: __thiscall CReverbTwo::CReverbTwo(void)" (??0CReverbTwo@@QAE@XZ)
1>C:UsersuserAppDataRoamingRackAFXPlugInsReverbTwo.dll : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

MinGW有关于在visual studio项目中使用MinGW库的说明:

http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs

关于不同编译器提供的库不一定兼容的原因,请参阅:

http://www.mingw.org/wiki/Interoperability_of_Libraries_Created_by_Different_Compiler_Brands