You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xcode下C/C++静态库与应用同步开发的正确配置问题

Xcode C静态库C++测试未定义符号修复操作指引
  • 打开静态库中包含void foo()实现的.c源文件,点击顶部菜单栏「View > Inspectors > Show File Inspector」调出右侧文件检查面板,在「Target Membership」区域,确认静态库对应target已勾选
  • 打开静态库对外暴露的头文件,在所有C函数声明外层添加如下包裹代码:
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    // 此处放置所有C函数声明,如void foo();
    
    #ifdef __cplusplus
    }
    #endif
    
  • 选中测试应用对应target,切换到「Build Phases」标签页,展开「Dependencies」分区,点击+号添加静态库对应的target,确保测试应用构建前会自动编译最新版本静态库
  • 分别选中静态库、测试应用的target,切换到「Build Settings」标签页,搜索Architectures配置项,确认两者的Architectures、Build Active Architecture Only配置完全一致,调试阶段建议将Build Active Architecture Only设为Yes
  • 选中测试应用target,切换到「Build Settings」标签页,搜索Other Linker Flags,添加-ObjC标记,如仍报错可追加-all_load标记
  • 按快捷键Shift + Command + K清理全局构建缓存,再按Command + B重新构建项目

内容的提问来源于stack exchange,提问作者MooseTech

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 02:15:03