Nm reports character but reporting character ldd undefined

I have a binding problem. I need to link to the libfoo.so shared library, which depends on the read function, which I would like to define in the read.c.

I compile and link everything together, but at runtime I get an error

 /home/bar/src/libfoo.so: undefined symbol: sread. 

nm reports that the character is defined

 $nm baz | grep sread 00000000000022f8 t sread 

but ldd reports that the character is undefined

 $ldd -r baz | grep sread undefined symbol: sread (/home/bar/src/libfoo.so) 

What gives? Is there some kind of isse with the fact that libfoo.so is a shared library?

+2
linux linker shared-libraries
source share
3 answers

First, defining a function called read is a bad idea (TM) because it is the standard libc function for all UNIXen. The behavior of your program is undefined at the same time.

Secondly, the read function you defined in libbaz.so is marked with the output of 't' in nm . This means that this function is local (not visible outside libbaz.so ). Global functions are marked with 't' on nm .

Do you use 'static int read(...)' when you defined it in read.c? If not, did you use the script or attribute((visibility(hidden))) -fvisibility=hidden or perhaps -fvisibility=hidden on the command line when you compiled and linked libbaz.so ?

+13
source share

The above error can also occur when C code is compiled with g ++ and then linked. g ++ does the name manipulation, so the actual character may be something like "_Zsds_ [function_name] _", causing the linker to choke when it searches for an intact name.

Today I encountered the same behavior, except that my problem was solved after the actions described in Wikipedia . Basically, C code compiled with the C ++ compiler will have a β€œgarbled” name in the character table, resulting in a C-style character resolution that fails.

+1
source share

When creating your shared library, you need to allow all undefined characters from either the same library or from another (shared) library. The linker will not allow the undefined character from the library with the character from your application.

-one
source share

All Articles