0

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

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

为此,首先在 C 中创建一个包装器,以调用dll要在 C 程序中使用的方法。我有注意,我确保我声明函数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

有人知道我做错了什么吗?

4

1 回答 1

1

您是否在包装方法源文件中包含外部“C”函数声明头文件?如果没有,就会出现这个错误

于 2013-08-29T01:29:23.707 回答