iOS链接错误,Undefined symbols for architecture arm64:std::__1::basic_string<char, std::__1::char_traits<

最近在开发和iOS相关的程序,需要和C++混编,做了几个静态库,之后整个app整合一下,结果在整合过程中遇到问题,总是提示链接错误:

Undefined symbols for architecture arm64:

  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(unsigned long, char)", referenced from:

      std::__1::wstring_convert<std::__1::codecvt_utf8<wchar_t, 1114111ul, (std::__1::codecvt_mode)0>, wchar_t, std::__1::allocator<wchar_t>, std::__1::allocator<char> >::to_bytes(wchar_t const*, wchar_t const*) in librender_sketcher_x6b64usd.a(sketcher_helper.o)

  "std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >::resize(unsigned long, wchar_t)", referenced from:

      std::__1::wstring_convert<std::__1::codecvt_utf8<wchar_t, 1114111ul, (std::__1::codecvt_mode)0>, wchar_t, std::__1::allocator<wchar_t>, std::__1::allocator<char> >::from_bytes(char const*, char const*) in librender_sketcher_x6b64usd.a(sketcher_helper.o)

  "std::exception_ptr::~exception_ptr()", referenced from:

      std::__1::packaged_task<void ()>::operator()() in librender_sketcher_x6b64usd.a(thread_pool_impl-10874E7367B0837E.o)

...

一看是找不到c++相关符号的定义,搞了半天终于有所收获:

可以把app中的任何一个.m文件扩展名改为.mm,即可解决链接错误

亦或 在app的引用库中显示引用 libstdc++.dylib 也可解决此问题


其道理就是只要app中存在.mm文件则app会自动添加对c++库的引用


另外XCODE也有一个问题:我在app中使用NSClassFromString 进行反射时,被反射类在另外一个静态库中,并且该app没有包含该库对应类的头文件,反射后始终返回nil,必须在Build setting的Other link flag中加入-all_load选项才能反射成功


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值