Technorati tags: C ++, rumtime, symbol lookup Error
When I encountered a problem in programming today, I was right when I didn't add a namespace to a class, and the operation was completely correct. However, when I added the namespace, the compilation was correct, but an error occurred during the running:
../Bin/test_gbr: Symbol lookup error: ../bin/test_gbr: Undefined Symbol: _ zn1_br9ksdensityc1epkdiissss.
I thought the namespace name had a conflict, so I changed the name and found that it was still the same and wrong. Then test other classes with the same namespace. There is no problem with this class alone.
Ask for help, Google a bit, "namespace Class symbol lookup error C ++", the first is the answer: http://gdwarner.blogspot.com/2009/03/c-runtime-symbol-lookup-error.html.
The full text is reproduced as follows:
C ++ RunTime "symbol lookup error"
I was working on a C ++ project. Everything linked and compiled fine. Upon running the executable, I got the following error:
./Testcppprogram: Symbol lookup error:./testcppprogram: Undefined Symbol: _ zn12cppprogramc1ev
I searched the internet. Two of the interesting links I found were the following:
- Http://osdir.com/ml/gcc.g++.general/2005-02/msg00061.html
- Http://www.linuxquestions.org/questions/linux-software-2/undefined-symbol-cout-263568/
For me it ended up being a bad LD_LIBRARY_PATH.The path I intended the executable to find it's needed shared library was in the LD_LIBRARY_PATH, It just wasn' t before a different path which had an older version of the needed shared library. (This happened to me when I updated by bashrc with a library path and just re-sourced it ).
Some cool commands in the debugging process:
- LDD testcppprogram(Shows you where your program is getting it's libraries from. An early-on careful inspection of this wocould 've quickly let me to my problem !)
- LDD-d-r testcppprogram(Shows you any undefined symbols. there shouldn't be any undefined symbols for an executable, but there will be for a shared lib if it depends on another shared Lib. somebody please correct me if I'm wrong)
- NM testcppprogram | C ++ filt(Displays unmangled Symbol Information)
- NM testcppprogram(Displays mangled symbol information. IE: You shoshould be able to find stuff like zn12cppprogramc1ev in here. in my problem above, I found which line number the undefined symbol in question was on, and then looked it up in the unmangled version to see what function it was trying to resolve. it let me know, But it didn't really help me find out what my problem was .)
- Readelf-D testcppprogram(Shows library dependencies. Similar to LDD .)
I found that my problem is the same as that of the author. My GBR needs to be compiled into a shared library, and then I will install it in my own directory $ usr_lib. But every time I re-compile GBR, the newly generated libgbr. so is not automatically installed to the $ usr_lib directory in the local directory, so libgbr in $ usr_lib. so is always old, that is, it does not use namespace. When running the executable file, the system automatically finds that libgbr. So in $ usr_lib is not updated, so an error occurs every time.
The solution is simple. Update libgbr. So in $ usr_lib to the latest version. Then test and run correctly.