[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dlsym() and C++



It's not that it doesn't work under C++.  C++ does name mangling to allow
for multiple functions with the same name.  For example using nm on
libcore.so without the extern "C" code gives the following:

000004b4 T ugga7__Fi
000004e4 T ugga7__Fii
00000498 T ugga__Fv

If you tried dlsym on ugga__Fv it should work.  However since there isn't
a specific name mangling standard every compiler can implement it
differently.  To avoid dealing with this most people make the function
extern "C" which stops the name mangling.

BTW it would be best to check if symbol is NULL before calling it
although maybe that was just for this sample code.

Dennis Payne
dulsi@identicalsoftware.com