adding symbols: DSO missing from command line collect2: error: ld returned 1 exi...
🚨 错误信息
cd /data/gerrit/workspace_Chery_repo/SenseMemory/build_linux_x86_64/Tests/integration && /snap/cmake/1507/bin/cmake -E cmake_link_script CMakeFiles/test_SenseMemory_components.dir/link.txt --verbose=1
/usr/bin/c++ -Wl,--build-id=sha1 CMakeFiles/test_SenseMemory_components.dir/test_sensememory_components.cpp.o ../../Common/CMakeFiles/Common.dir/Utils/src/BuildInfo.cpp.o ../../Common/CMakeFiles/Common.dir/Utils/src/Uuid.cpp.o ../../Common/CMakeFiles/Common.dir/Utils/src/uuid4.c.o ../../Common/CMakeFiles/Common.dir/VpAccount/src/VpAccount.cpp.o ../../Common/CMakeFiles/Common.dir/protoco/sensememory.pb.cc.o -o ../../bin/test_SenseMemory_components -L/data/gerrit/workspace_Chery_repo/SenseMemory/../qc8797_Linux/thirdparty/kuzu/linux-x86_64/lib -Wl,-rpath,/data/gerrit/workspace_Chery_repo/SenseMemory/../qc8797_Linux/thirdparty/kuzu/linux-x86_64/lib:/data/gerrit/workspace_Chery_repo/SenseMemory/build_linux_x86_64/lib ../../lib/libMemory.so -lpthread -lprotobuf -lkuzu
/usr/bin/ld: warning: libprotobuf.so.32, needed by ../../lib/libMemory.so, may conflict with libprotobuf.so.23
/usr/bin/ld: ../../Common/CMakeFiles/Common.dir/protoco/sensememory.pb.cc.o: undefined reference to symbol '_ZN6google8protobuf8internal14ArenaStringPtr12ClearToEmptyEv'
/usr/bin/ld: /data/gerrit/workspace_Chery_repo/SenseMemory/../qc8797_Linux/razor/linux-x86_64/lib/libprotobuf.so.32: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
🤖 AI解决方案
代码报错分析报告
根本原因:protobuf库版本冲突问题。
但链接命令中指定的是
这导致符号不匹配,因为不同版本的protobuf ABI不兼容
版本一致性:确保所有依赖组件使用相同版本的第三方库,避免ABI兼容性问题
显式库路径:使用完整路径链接库文件,而不是依赖系统的
1. 错误翻译
原文:/usr/bin/ld: warning: libprotobuf.so.32, needed by ../../lib/libMemory.so, may conflict with libprotobuf.so.23
译文:链接器警告:../../lib/libMemory.so 需要 libprotobuf.so.32,可能与 libprotobuf.so.23 冲突原文:/usr/bin/ld: ../../Common/CMakeFiles/Common.dir/protoco/sensememory.pb.cc.o: undefined reference to symbol '_ZN6google8protobuf8internal14ArenaStringPtr12ClearToEmptyEv'
译文:链接器错误:sensememory.pb.cc.o 存在未定义的符号引用(protobuf内部函数)
原文:/usr/bin/ld: /data/gerrit/.../libprotobuf.so.32: error adding symbols: DSO missing from command line
译文:链接器错误:添加符号时出错,DSO缺失于命令行
2. 原因分析
根本原因:protobuf库版本冲突问题。
具体分析:
libMemory.so 需要 libprotobuf.so.32(protobuf 3.2+版本)-lprotobuf,可能链接到系统默认的 libprotobuf.so.23(protobuf 2.3版本)3. 解决方案
方法一:明确指定正确的protobuf库路径
cmake
在CMakeLists.txt中添加
find_library(PROTOBUF_LIB NAMES libprotobuf.so.32
PATHS /data/gerrit/workspace_Chery_repo/SenseMemory/../qc8797_Linux/razor/linux-x86_64/lib)
target_link_libraries(your_target ${PROTOBUF_LIB})
方法二:修改链接命令
bash
替换原有的 -lprotobuf
-Wl,-rpath,/data/gerrit/workspace_Chery_repo/SenseMemory/../qc8797_Linux/razor/linux-x86_64/lib \
/data/gerrit/workspace_Chery_repo/SenseMemory/../qc8797_Linux/razor/linux-x86_64/lib/libprotobuf.so.32
方法三:更新CMake配置
cmake
在CMakeLists.txt中
set(CMAKE_PREFIX_PATH "/data/gerrit/workspace_Chery_repo/SenseMemory/../qc8797_Linux/razor/linux-x86_64")
find_package(Protobuf REQUIRED)
target_link_libraries(your_target ${PROTOBUF_LIBRARIES})
4. ️ 预防措施
最佳实践建议
-l 查找机制推荐检查方法
bash
1. 检查库文件依赖关系
ldd ../../lib/libMemory.so | grep protobuf2. 查看链接命令中的库搜索路径
echo $LD_LIBRARY_PATH3. 验证库文件版本
strings /path/to/libprotobuf.so | grep -i "protobuf.*version"
---
关键提示:此错误是典型的版本冲突问题,在编译大型项目时尤其常见。确保整个构建系统使用统一的protobuf版本是关键。