如何解决这个错误“:(。text + 0x4d):未定义引用`_imp___ZN10Management11OpenEm'”

时间:2013-08-28 16:24:58

标签: c++ c linker cygwin wrapper

我需要在C程序中调用C ++程序中的一些方法。

但我只有一个共享库(.dll)来使用这些方法。

为了实现它,首先在C中创建一个包装器,以调用要在C程序中使用的dll的方法。我已经注意了,并确保我使用extern "C"声明函数以避免名称错误。

但是当编译时,.o的链接墙有一组错误(如下所示):

g++ -o bonnie++ bonnie++.o bon_io.o bon_file.o bon_time.o semaphore.o sync.o thread.o bon_suid.o duration.o rand.o util.o utils.o super.o pcm_file.o inode.o iname.o dir.o pcm.o -lpthread -L./ -lSmart
pcm.o:pcm.c:(.text+0x4d): undefined reference to `_imp___ZN10Management11OpenEm'
pcm.o:pcm.c:(.text+0x64): undefined reference to `_imp___ZN10Management12CloseEm'
pcm.o:pcm.c:(.text+0x73): undefined reference to `_imp___ZN10Management17EnumerateEv'
pcm.o:pcm.c:(.text+0xb9): undefined reference to `_imp___ZN18DemonstratorDevC1Ev'
pcm.o:pcm.c:(.text+0xf7): undefined reference to `_imp___ZN18DemonstratorDevD1Ev'
pcm.o:pcm.c:(.text+0x121): undefined reference to `_imp___ZN18DemonstratorDevice11OpenEi'
pcm.o:pcm.c:(.text+0x138): undefined reference to `_imp___ZN18DemonstratorDev12CloseAdapterEv'
pcm.o:pcm.c:(.text+0x15f): undefined reference to `_imp___ZN18DemonstratorDev23ConfigureClockFrequencyEi15_ClockFrequency'
pcm.o:pcm.c:(.text+0x176): undefined reference to `_imp___ZN18DemonstratorDev21AdaptationBlockEnableEv'
pcm.o:pcm.c:(.text+0x1a1): undefined reference to `_imp___ZN18CommandsManagementC1ER18DemonstratorDev'
pcm.o:pcm.c:(.text+0x1df): undefined reference to `_imp___ZN18CommandsManagementD1Ev'
pcm.o:pcm.c:(.text+0x21a): undefined reference to `_imp___ZN18CommandsManagement20DeviceInitializationEim9TimerCtrl'
pcm.o:pcm.c:(.text+0x253): undefined reference to `_imp___ZN18CommandsManagement24EnableEmbeddedOperationsER8OWStatusim9TimerCtrl'
pcm.o:pcm.c:(.text+0x290): undefined reference to `_imp___ZN18CommandsManagement12RegionUnlockEmmim9TimerCtrl'
pcm.o:pcm.c:(.text+0x2da): undefined reference to `_imp___ZN18CommandsManagement17BufferedOverwriteEmmPKhiiim9TimerCtrl'
pcm.o:pcm.c:(.text+0x32c): undefined reference to `_imp___ZN18CommandsManagement9BurstReadEmPtmih9BurstTypeim9TimerCtrl'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: pcm.o: bad reloc address 0x20 in section `.eh_frame$_ZN10ManagementC1Ev'
collect2: error: ld returned 1 exit status
Makefile:37: recipe for target `bonnie++' failed
make: *** [bonnie++] Error 1

有人知道我做错了吗?

1 个答案:

答案 0 :(得分:1)

您是否在包装器方法源文件中包含extern“C”函数声明头文件?如果没有,将发生此错误