xcode下出现Undefined symbols for architecture arm64或者armv7: “_OBJC_CLASS_$_XXX

碰到一个类似上述的问题,感觉还是stl的C++库加载造成的问题。

即使通过gcc -v查看了编译过程,

然后用gcc -E 导出了预编译后的文件,

查看到的仍然只是std::string,为什么会出现接口中

有的是fucn(std::string)

有的是func(std::__1::basic_string...)

仍然没有搞清楚,网上有一篇似乎可以处理这个问题的文章,如下:

http://blog.csdn.net/kaizi318/article/details/10362673 

但是尝试后,发现xcode仍然报错。

通过在后台用nm查看调用。

发现如果用libstdc++库,则需要使用指定头文件,添加头文件路径如下:

-I $(shell $(XCRUN) --show-sdk-path)/usr/include/c++/4.2.1

其对应使用的std::string类型就是std::string。

而若是不指定用libstdc++,而是使用默认的libc++库,则使用的是默认的C++头文件,

其对应使用的std::string变成了std::__1::basic_string(........)之类的

因此,c++头文件使用的不同导致其他使用stl的库的函数签名和实现都不同了

参考文章如下:

Undefined symbols for architecture i386或者armv7: “_OBJC_CLASS_$_XXX

Undefined symbols for architecture i386:
“_OBJC_CLASS_$_XXX”,  referen ced from:
objc-class-ref in XXX

ld: symbol(s) not found for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)


如果真机调试就是 undefined symbols for architecture armv7错误!
发生这种错误通常是project.pbxproj这个文件引起的,尤其在多人合作开发的时候,svn提交不规范可能导致project.pbxproj发生错误,导致文件的引用不在project.pbxproj文件中。
xcode项目import文件会根据project.pbxproj来查找,查找不到文件的引用则会有上述的错误。

解决方法点击工程,在主界面中点击Build Phases,根据提示信息“XXX”来判断缺少什么文件,一般如果缺少自定义的文件,XXX会是缺少的类名,那么就在Complie Sources中加入该文件。如果缺少类库,则在Link Binary With Libraries中加入该类库。

Undefined symbols for architecture i386:
02   "TextureMan::LoadTexture(std::__1::basic_string, std::__1::allocator > const&, int, bool)", referenced from:
03       tolua_gameinterface_TextureMan_loadTexture00(lua_State*) inlibCoreClientiOS.a(tolua_gameinterface.o)
04   "SoundManager::BgndMusicPlay(std::__1::basic_string, std::__1::allocator > const&, bool)", referenced from:
05       tolua_gameinterface_SoundManager_BgndMusicPlay00(lua_State*) inlibCoreClientiOS.a(tolua_gameinterface.o)
06   "SoundManager::BgndMusicStop(std::__1::basic_string, std::__1::allocator > const&, bool)", referenced from:
07       tolua_gameinterface_SoundManager_BgndMusicStop00(lua_State*) inlibCoreClientiOS.a(tolua_gameinterface.o)
08   "Font::LoadFont(std::__1::basic_string, std::__1::allocator > const&)", referenced from:
09       tolua_gameinterface_Font_loadFont00(lua_State*) inlibCoreClientiOS.a(tolua_gameinterface.o)
10   "System::MakeDocumentPath(std::__1::basic_string, std::__1::allocator > const&) const", referenced from:
11       tolua_gameinterface_System_makeDocumentPath00(lua_State*) inlibCoreClientiOS.a(tolua_gameinterface.o)
12   "System::MakeResourcePath(std::__1::basic_string, std::__1::allocator > const&) const", referenced from:
13       ExUnit::LogicThread::Run() in libCoreClientiOS.a(logicthread.o)
14       tolua_gameinterface_System_makeResourcePath00(lua_State*) inlibCoreClientiOS.a(tolua_gameinterface.o)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值