I'm trying to link a small C++ test program, main.o
to a 3rd party static library, but get some inexplicable undefined reference
errors.
Specifically:
g++ -o secoTest -lpthread main.o libEAPI.a
main.o: In function `main':
main.cpp:(.text+0x29fe): undefined reference to `EApiWDog_SetConfigAndStart(unsigned int, unsigned int, unsigned int, unsigned int, unsigned char, unsigned char, unsigned char)'
main.cpp:(.text+0x33fc): undefined reference to `EApiSetCarrier(unsigned char)'
main.o:main.cpp:(.text+0x3956): more undefined references to `EApiSetCarrier(unsigned char)' follow
main.o: In function `main':
main.cpp:(.text+0x3965): undefined reference to `EApiGPIOGetSerialCfg(unsigned char*)'
main.cpp:(.text+0x3a0a): undefined reference to `EApiSetCarrier(unsigned char)'
main.cpp:(.text+0x3a19): undefined reference to `EApiGPIOSetSerialCfg(unsigned char)'
main.cpp:(.text+0x3adf): undefined reference to `EApiFanEnable(unsigned int, unsigned char)'
main.cpp:(.text+0x3b83): undefined reference to `EApiFanDisable()'
collect2: ld returned 1 exit status
However, it seems the symbols are present in the library. For example:
nm --demangle libEAPI.a | grep EApiFanDisable
00003c20 T EApiFanDisable
The strange thing is the symbols are not exactly the same. In main.o
it is
nm --demangle main.o | grep EApiFanDisable
U EApiFanDisable()
So one has ()
and one doesn't.
Similarily,
nm --demangle main.o | grep EApiSetCarrier
U EApiSetCarrier(unsigned char)
nm --demangle libEAPI.a | grep EApiSetCarrier
000015d0 T EApiSetCarrier
If I leave out the library altogether from the command line (eg, g++ -o secoTest -lpthread main.o
) it shows lots of errors as expected.
main.o
references external symbols with and with ()
[why?]:
U EApiVgaSetBacklightEnable
U EApiWDogStart
U EApiWDogTrigger
U EApiFanEnable(unsigned int, unsigned char)
U EApiFanDisable()
U EApiSetCarrier(unsigned char)
But the library has only symbols without ()
[why?]:
000020e0 T EApiVgaSetBacklightEnable
000024e0 T EApiWDogStart
000026f0 T EApiWDogTrigger
00003c20 T EApiFanDisable
00003bf0 T EApiFanEnable
000015d0 T EApiSetCarrier
Would that be the reason for the undefined references? How would I fix it? Not sure where to look next...
(I cannot modify the 3rd party library but have the header files.)
EDIT
As lisyarus suggested, here is the nm
without the --demangle
. Indeed, the symbols are different. The g++ compiler (v4.4.7) generates a mangled symbol for some symbols only while the library always has plain symbols... [why?]
nm libEAPI.a main.o | grep EApiWDogTrigger
000026f0 T EApiWDogTrigger
U EApiWDogTrigger
nm libEAPI.a main.o | grep EApiSetCarrier
000015d0 T EApiSetCarrier
U _Z14EApiSetCarrierh