公司动态

共享库文件查看内部

📅 2026/8/10 9:11:15
共享库文件查看内部
CMAKE .so一、查看 CMake 最终生效的编译选项两种方案方案1打印目标所有 compile options推荐精准看target_compile_options在 CMake 脚本末尾添加这段代码替换stixelworld_shared/${PROJECT_NAME}为你的目标名function(print_target_compile_options TARGET) get_target_property(opts ${TARGET} COMPILE_OPTIONS) get_target_property(pub_opts ${TARGET} INTERFACE_COMPILE_OPTIONS) message(STATUS ) message(STATUS [${TARGET}] PRIVATE COMPILE_OPTIONS: ${opts}) message(STATUS [${TARGET}] INTERFACE/PUBLIC COMPILE_OPTIONS: ${pub_opts}) message(STATUS ) endfunction() # 调用填入你的目标 print_target_compile_options(stixelworld_shared) print_target_compile_options(stixelworld) print_target_compile_options(GODService)区分target_compile_options(tgt PRIVATE xxx)→ COMPILE_OPTIONStarget_compile_options(tgt PUBLIC xxx)→ 同时进入 COMPILE_OPTIONS INTERFACE_COMPILE_OPTIONStarget_compile_options(tgt INTERFACE xxx)→ INTERFACE_COMPILE_OPTIONS方案2查看完整最终传给编译器的命令最真实方式A利用CMAKE_EXPORT_COMPILE_COMMANDSON你已经开启构建目录生成compile_commands.json直接打开文件搜索目标源码main.cpp / Stixel_Detect.cpp可以看到完整 g/aarch64-none-linux-gnu-g 命令行所有-std -O3 -g -Wall全部打印。方式Bmake 输出完整编译指令make VERBOSE1执行后每一条编译命令完整打印aarch64-none-linux-gnu-g -stdc14 -Wall -O3 -g -c src/main.cpp ...✅ 最直观直接对比so库编译时使用什么-std可执行文件GODService编译使用什么-std快速定位ABI不匹配之前undefined reference核心嫌疑点二、针对你工程的关键问题提醒compile_options 陷阱陷阱1全局 CMAKE_CXX_FLAGS 和 target_compile_options 叠加冲突# GODService set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -stdc14 -g -Wall -O3 ) #全局flag set(CMAKE_CXX_STANDARD 17) # stixelworld_shared target_compile_options(stixelworld_shared PUBLIC -stdc14 -Wall -O3)CMAKE_CXX_STANDARD** 会自动添加-stdc17到编译器参数**同时又手动传入-stdc14GCC行为后面出现的 -std 覆盖前面顺序不确定极易造成时而c14、时而c17→ 符号名 mangling 不一致 → undefined reference✅ 规范写法二选一不要混用推荐只用 CMAKE_CXX_STANDARD禁止手动写-stdxxset(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # target_compile_options 不再添加 -stdxxx target_compile_options(stixelworld_shared PUBLIC -Wall -O3)陷阱2PUBLIC compile_options 传染依赖方target_compile_options(stixelworld_shared PUBLIC -stdc14)所有链接stixelworld_shared的目标stixelworld可执行文件会自动继承-stdc14。但是跨工程GODService 是独立工程不是同一个cmakePUBLIC 完全无效 GODService 不会继承 stixelworld_shared 的任何 compile_options必须自身单独配置标准。三、直接给你加到现有CMake的完整示例stixelworld CMake 修改片段# 删除 target_compile_options 内的 -stdc14 target_compile_options(stixelworld_shared PUBLIC -Wall -O3) # 打印编译标记 function(print_target_compile_options TARGET) get_target_property(opts ${TARGET} COMPILE_OPTIONS) get_target_property(pub_opts ${TARGET} INTERFACE_COMPILE_OPTIONS) message(STATUS \n Target: ${TARGET} ) message(STATUS PRIVATE opts: ${opts}) message(STATUS INTERFACE opts: ${pub_opts}) endfunction() print_target_compile_options(stixelworld_shared) print_target_compile_options(stixelworld)GODService CMake 修改片段# 删除 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) # 删除全局 CMAKE_CXX_FLAGS 里面的 -stdc14 set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -g -Wall -O3 ) # 增加打印 function(print_target_compile_options TARGET) get_target_property(opts ${TARGET} COMPILE_OPTIONS) get_target_property(pub_opts ${TARGET} INTERFACE_COMPILE_OPTIONS) message(STATUS \n Target: ${TARGET} ) message(STATUS PRIVATE opts: ${opts}) message(STATUS INTERFACE opts: ${pub_opts}) endfunction() print_target_compile_options(GODService)四、快速调试流程建议两个工程全部移除所有手写-stdcxx使用CMAKE_CXX_STANDARD14统一标准make VERBOSE1分别编译 stixelworldaarch64、GODService对比两条编译命令中的-std参数必须完全一致确认交叉编译器是同一个aarch64-none-linux-gnu-g 12.2.1如果你需要我可以直接帮你完整修正两份CMake脚本消除std冲突隐患。