Linux: C++ lookup error – undefined symbol

At a customer site, we had a C++ program (renamed for the purpose of this blog to myprogram) which was failing after running for some time. It’s a program processing messages from an external system and seemed to fail only when the processing of the message triggered some given operations. The error message was:

lookup error: /home/xxx/bin/xxx/myprogram: undefined symbol: _Z22CxxxPxxxExxxPxxxR6CDBManRKSsRSt6vectorISsSaISsEE

The first thought was to use ldd to check whether everything was fine:

# ldd myprogram =>  (0xffffe000) => not found => not found => not found => not found => not found => not found => not found => /lib/ (0x4001e000) => /usr/lib/ (0x40022000) => /lib/tls/ (0x400df000) => /lib/ (0x40101000) => /lib/tls/ (0x40109000)
        /lib/ (0x40000000)

So many not found ! Ok I must have forgotten something… Of course, LD_LIBRARY_PATH is probably not set in my shell:

# pidof myprogram
# export `cat /proc/10132/environ | strings | grep LD_LIBRARY_PATH`
  • pidof return the id of the process running the specified program
  • /proc/10132/environ contains the whole environment of the specified process
  • strings is required to convert the 0x00 separated strings of /proc/xxx/environ
  • The rest just gets the line LD_LIBRARY_PATH=… and uses export to set it in my shell as well

Now I have the same LD_LIBRARY_PATH as the process running myprogram and can rerun ldd:

ldd myprogram =>  (0xffffe000) => /home/xxx/libs/ (0x40018000) => /home/xxx/libs/ (0x40051000) => /opt/sybase-12.5/OCS-12_5/lib/ (0x403a5000) => /home/xxx/libs/ (0x404e1000) => /home/xxx/libs/ (0x405c5000) => /home/xxx/libs/ (0x4068d000) => /home/xxx/libs/ (0x40695000) => /lib/ (0x40985000) => /usr/lib/ (0x40988000) => /lib/tls/ (0x40a46000) => /lib/ (0x40a68000) => /lib/tls/ (0x40a70000) => /usr/lib/ (0x40b8a000) => /lib/tls/ (0x40bd2000)
        /lib/ (0x40000000)

Everything looks OK. So it’s not that a library is missing. Also the paths to the libraries are OK.

Executing ldd -r -d myprogram basically just shows me the same plus an error with the missing symbol.

Finally, comparing the size of the library files on this system and at another customer site with the exact same version of the software gave us the answer: somehow a different version of one of our library landed there and didn’t contain the missing symbol.

So the search ended there. Otherwise we’d have had to use the following:

Use c++filt to find out the method behind the mangled symbol name:

# c++filt _Z22CxxxPxxxExxxPxxxR6CDBManRKSsRSt6vectorISsSaISsEE
CxxxPxxxExxxPxxx(CDBMan&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)

Use nm to list the symbols in the libraries shown by ldd:

# nm /home/xxx/libs/

This will show the mangled symbol names. For demangled symbols, use the -C option:

 # nm -C /home/xxx/libs/

2 thoughts on “Linux: C++ lookup error – undefined symbol

  1. This is a well known issue in windows and is known as DLL hell. Except in windows, the application would propably not load at all. ‘Probably’… because you can load a DLL on first access or in the normal case you load the DLL at the start.

    Good Work!! Keep up the blog.

  2. i have learned a lot of new commands for analyzing so files and probably saved at least an hour of strugglement. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *