adding symbols: DSO missing from command line collect2: error: ld returned 1 exi...
🚨 错误信息
/data/gerrit/workspace_AIBox_repo/Vendor/IC_NM_OrinX/aarch64--glibc--stable-2022.08-1/bin/../lib/gcc/aarch64-buildroot-linux-gnu/11.3.0/../../../../aarch64-buildroot-linux-gnu/bin/ld: CMakeFiles/SenseMemoryService.dir/SenseMemoryService.cpp.obj: undefined reference to symbol '_ZN9senseauto11sensememory18SenseMemory_Logger4InitENS0_20SenseMemory_LogLevelE'
/data/gerrit/workspace_AIBox_repo/Vendor/IC_NM_OrinX/aarch64--glibc--stable-2022.08-1/bin/../lib/gcc/aarch64-buildroot-linux-gnu/11.3.0/../../../../aarch64-buildroot-linux-gnu/bin/ld: /data/gerrit/workspace_AIBox_repo/AICore/IC_NM_SenseMemory/output/linux_orin/lib/libsenseauto_infrastructure.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
🤖 AI解决方案
错误分析与解决方案
- 错误翻译
/data/gerrit/workspace_AIBox_repo/Vendor/IC_NM_OrinX/aarch64--glibc--stable-2022.08-1/bin/../lib/gcc/aarch64-buildroot-linux-gnu/11.3.0/../../../../aarch64-buildroot-linux-gnu/bin/ld: CMakeFiles/SenseMemoryService.dir/SenseMemoryService.cpp.obj: undefined reference to symbol '_ZN9senseauto11sensememory18SenseMemory_Logger4InitENS0_20SenseMemory_LogLevelE'
# 核心关键句:未定义的引用符号 '_ZN9senseauto11sensememory18SenseMemory_Logger4InitENS0_20SenseMemory_LogLevelE'
/data/gerrit/workspace_AIBox_repo/Vendor/IC_NM_OrinX/aarch64--glibc--stable-2022.08-1/bin/../lib/gcc/aarch64-buildroot-linux-gnu/11.3.0/../../../../aarch64-buildroot-linux-gnu/bin/ld: /data/gerrit/workspace_AIBox_repo/AICore/IC_NM_SenseMemory/output/linux_orin/lib/libsenseauto_infrastructure.so: error adding symbols: DSO missing from command line
# 核心关键句:DSO (动态共享对象) 在命令行中缺失,添加符号时出错
collect2: error: ld returned 1 exit status
# 核心关键句:链接器(ld)返回了1个错误状态
链接器在尝试链接
SenseMemoryService.cpp.obj 文件时,发现它依赖的符号 _ZN9senseauto11sensememory18SenseMemory_Logger4InitENS0_20SenseMemory_LogLevelE 在 /data/gerrit/workspace_AIBox_repo/AICore/IC_NM_SenseMemory/output/linux_orin/lib/libsenseauto_infrastructure.so 这个动态共享库中找不到。这是因为在链接过程中,没有明确指定 libsenseauto_infrastructure.so 库。
在编译链接
SenseMemoryService 时,需要将 libsenseauto_infrastructure.so 库添加到链接器的搜索路径和需要链接的库列表中。
示例(以 CMake 为例):
假设您的 SenseMemoryService 目标是在 CMakeLists.txt 中定义的,您需要修改 target_link_libraries 命令,确保 libsenseauto_infrastructure 被链接。
# 假设 SenseMemoryService 是您的目标名
target_link_libraries(SenseMemoryService PRIVATE
# ... 其他库
libsenseauto_infrastructure # 确保此库被列出
# 如果库不在标准路径,可能需要设置 link_directories
# link_directories(/path/to/your/lib)
)
如果使用命令行编译:
在 g++ 或 ld 命令中,添加 -L 指定库所在的目录,并添加 -lsenseauto_infrastructure。
g++ ... -L/data/gerrit/workspace_AIBox_repo/AICore/IC_NM_SenseMemory/output/linux_orin/lib -lsenseauto_infrastructure ...
* 依赖管理:在项目中使用一个可靠的依赖管理工具,确保所有必要的库在构建时都被正确声明和链接。
* 构建脚本审查:定期审查项目的构建脚本(如 CMakeLists.txt、Makefile),确认所有动态库的链接配置是完整且正确的。