1827769 Members
2712 Online
109969 Solutions
New Discussion

dlsym error

 
Sridhar B V
New Member

dlsym error

Hi,

I have created a shared library as below:

1. # aCC -c +z myshlib.cxx
2. # ld -b -o libtest.so myshlib.o

Now I wrote a sample program which loads this library through dlopen() and loads succesfully. When I search a symbol using dlsym it flashes an error saying unknown symbol. Here is the steps:

3. # aCC sample.cxx -o result
4. ./result
dlsym: Unknown symbol sum

I have attached both myshlib.cxx and sample.cxx

Below is the machine details and compiler version.

# uname -a
HP-UX bv750 B.11.31 U ia64 0223118237 unlimited-user license
# aCC -V
aCC: HP C/aC++ B3910B A.06.23 [May 18, 2009]

Any inputs will be greatly appreciated. Thank you.
4 REPLIES 4

Re: dlsym error

in C++ symbol names will be mangled. in your case, 'sum' is mangled as '_Z3sumii'. so if you dlsym for the mangled name, your test case works.

if you dont want certain symbols to be mangled, use them within an 'extern "C"{}' block...
Dennis Handly
Acclaimed Contributor

Re: dlsym error

>Suprateeka: if you don't want certain symbols to be mangled, use them within an 'extern "C" {}' block.

Right. Also your pointer to function should be in one too:
extern "C" {
typedef int (*PIFII)(int, int);
}
...
PIFII fun;
fun = (PIFII)dlsym(dl_handle, "sum");
Sridhar B V
New Member

Re: dlsym error

Thank you all. The suggestions worked.

Can anyone suggest a material regarding the given solution to learn about it and more.
Dennis Handly
Acclaimed Contributor

Re: dlsym error

>Can anyone suggest a material regarding the given solution to learn about it

Not much here:
http://docs.hp.com/en/14487/gloss.htm#n

Here is the ia64 mangling rules:
http://www.codesourcery.com/public/cxx-abi/abi.html#mangling

Basically you need to do mangling if you want to have overloading of functions and nested functions.