The error message you're encountering, ./vp: symbol lookup error: ../lib/libnavi_app_unit_test_x5h.so: undefined symbol: _Z9uint_sqrtj, indicates a runtime linker issue. Specifically, it's saying that the binary vp you are trying to run depends on a shared library libnavi_app_unit_test_x5h.so, which in turn requires a symbol (function or variable) named _Z9uint_sqrtj that it cannot find at runtime. The symbol _Z9uint_sqrtj is the mangled name for a function, likely uint_sqrt(unsigned int), based on C++ name mangling conventions.
Here are the common reasons for this issue and how to resolve it:
1. The Missing Symbol is Not Defined
The most straightforward reason would be that the required function uint_sqrt(unsigned int) is declared but not defined in any of the linked object files or libraries. This could happen for a few reasons:
- The implementation of
uint_sqrt is missing from the source files.
- The object file or library containing
uint_sqrt was not included during the linking process.
Solution: Ensure that the function uint_sqrt(unsigned int) is properly implemented in your source code and that all relevant source files are included in the build process.
2. Incorrect Library Order in Linking
If the function is defined in another library that libnavi_app_unit_test_x5h.so depends on, it's possible that the libraries are not linked in the correct order. The linker processes libraries in the order they're provided, so if a library that defines a symbol is listed before a library that needs it, the linker won't backtrack to resolve the symbol.
Solution: Adjust the order of the libraries during the linking process so that dependent libraries are listed after their dependencies.
3. Library Path Issues
If uint_sqrt is defined in a shared library that is not in the standard library paths, the runtime linker (ld.so or similar) might not be able to find the library containing the definition of uint_sqrt at runtime.
Solution:
- Ensure that the library providing
uint_sqrt is correctly installed and located in a directory that is part of the runtime linker's search path.
- Use the
LD_LIBRARY_PATH environment variable to add directories to the linker's search path at runtime.
- Use
rpath or RUNPATH linker options to embed search paths directly into the binary or library.
4. Versioning Issues
If the library providing uint_sqrt has multiple versions, and the wrong version is being used (one that doesn't have uint_sqrt), you might encounter this error.
Solution: Ensure that the correct version of the library is being linked against and is accessible to the runtime linker.
5. Symbol Visibility Issues
It's also possible that the symbol is being compiled with hidden visibility and thus is not available for dynamic linking.
Solution: Ensure that the symbol is compiled with default visibility. In GCC and Clang, this can often be controlled with __attribute__((visibility("default"))) or compile-time flags.
Diagnostic Tools
To diagnose and fix this issue, you can:
- Use the
nm tool on UNIX-like systems to check if uint_sqrtj is indeed defined in any of the object files or libraries. nm -C libname.so | grep uint_sqrt can be used, where -C demangles the symbols.
- Use tools like
ldd to see which dynamic libraries are actually being loaded at runtime.
- Ensure your build process correctly includes and links all the necessary sources and libraries.
Addressing the cause of the missing symbol as outlined above should help in resolving the error you're facing.