Search code examples
c++clinkercygwinwrapper

How to solve this error ":(.text+0x4d): undefined reference to `_imp___ZN10Management11OpenEm'"


I need to call some methods from a C++ program in a C program.

But I just have one shared library (.dll) to use those methods.

To make it, first a create a wrapper in C to call the methods from the dll to be used in the C program. I have attention and I make sure that I declare the functions with extern "C" to avoid name mangling.

But when a compile I have a set of errors (shown in down) when a linking wall the .o's:

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

Someone know what I am doing wrong?


Solution

  • Do you include the extern "C" function declaration header files in your wrapper method source file? if not, this error will occur