Cocos2d-x 在Xcode的Undefined symbols for architecture x86_64错误

Cocos2d-x : About Undefined symbols for architecture x86_64 Error

Posted by SunnyRx on January 14, 2016

在Windows环境下用cocos2d-x完成了一个程序,搬到Mac后编译出错,出错信息如下。

Undefined symbols for architecture x86_64:
  "EasyButton::createEasyButton(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      SettingScene::init() in SettingScene.o
  "RadioButton::createRadioButton(EasyButton*, ...)", referenced from:
      SettingScene::init() in SettingScene.o
  "RadioButton::getSelectedNumber()", referenced from:
      SettingScene::test() in SettingScene.o
  "RadioButton::setSelectedNumber(int)", referenced from:
      SettingScene::init() in SettingScene.o
  "ScriptReader::jumpToSign(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      GameScene::showSelect(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&)::$_4::operator()(cocos2d::Ref*) const in GameScene.o
  "ScriptReader::jumpToSign(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
      GameScene::reloadScene() in GameScene.o
  "ScriptReader::nextScript()", referenced from:
      GameScene::init() in GameScene.o
      GameScene::dialogClicked() in GameScene.o
      GameScene::autoPlay(float) in GameScene.o
  "ScriptReader::getInstance()", referenced from:
      GameScene::init() in GameScene.o
      GameScene::reloadScene() in GameScene.o
      GameScene::dialogClicked() in GameScene.o
      GameScene::autoPlay(float) in GameScene.o
      GameScene::createGameDate() in GameScene.o
      GameScene::showSelect(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&)::$_4::operator()(cocos2d::Ref*) const in GameScene.o
      GameSystem::saveGameSceneInfo(int) in GameSystem.o
      ...
  "ScriptReader::initWithStage(cocos2d::Node*)", referenced from:
      GameScene::init() in GameScene.o
  "ScriptReader::loadScriptFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      GameScene::init() in GameScene.o
  "ScriptReader::getCurrentSignName()", referenced from:
      GameScene::createGameDate() in GameScene.o
      GameSystem::saveGameSceneInfo(int) in GameSystem.o
  "ScriptReader::getCurrentCommandIndex()", referenced from:
      GameScene::createGameDate() in GameScene.o
      GameSystem::saveGameSceneInfo(int) in GameSystem.o
  "CharactorManager::getInstance()", referenced from:
      GameScene::displayCharator(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in GameScene.o
      GameScene::unDisplayCharator(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in GameScene.o
      GameScene::reloadScene() in GameScene.o
  "CharactorManager::getCharactor(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)", referenced from:
      GameScene::displayCharator(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in GameScene.o
      GameScene::unDisplayCharator(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in GameScene.o
      GameScene::reloadScene() in GameScene.o
  "BackgroundManager::getInstance()", referenced from:
      GameScene::changeBackground(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in GameScene.o
      GameScene::reloadScene() in GameScene.o
  "BackgroundManager::getBackground(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      GameScene::changeBackground(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in GameScene.o
      GameScene::reloadScene() in GameScene.o
  "BackgroundMusicManager::getInstance()", referenced from:
      GameScene::playBackgroundMusic(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in GameScene.o
  "BackgroundMusicManager::getBackgroundMusic(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      GameScene::playBackgroundMusic(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in GameScene.o
  "Slidebar::createSlidebar(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      SettingScene::init() in SettingScene.o
  "Slidebar::getFloat()", referenced from:
      SettingScene::changeMusicVolume() in SettingScene.o
  "Slidebar::setFloat(float)", referenced from:
      SettingScene::init() in SettingScene.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

首先留意到的是第一句话:Undefined symbols for architecture x86_64 可能是不支持x86_64,在Build Settings->Architectures->ArchitecturesBuild Settings->Architectures->Valid Architectures可以改变设置。根据搜索到的方法进行改变设置后在编译时会出现其他错误(可能是改变设置的方法不对,所以在这里不展示改变设置的方法),而在不改变设置的情况下编译HelloWorld程序成功并且正常运行,因此推断与是否支持x86_64无关。

大部分错误都涉及std::map。 可能C++编译设置有问题,在Build Settings->Apple LLVM 7.0 - Language - C++中对C++ Language DialectC++ Standard Library进行设置,分别设置为C++11[-std=C++11]libc++或者两个都设置为Compilder Default。项目中默认已经设置为后者,同时单独写了一个调用std::map的方法,编译成功且正常运行,因此推断与设置无关。

所有错误表示,找到了方法的声明但找不到对应的实现。 检查了Xcode项目中的Classes文件夹,所有.h文件和.cpp均在其中。

而最终解决问题的方法是将Classes文件夹中的内容拖入Xcode目录中时,弹出的对话框Choose options for adding these files:中的Added folders选择Create groups,问题则解决。 Choose options对话框

尽管标题带有Cocos2d-x,实际上跟Cocos2d-x没有一点关系。 另外要注意,将Resources文件夹拖入Xcode目录时,应该选择Create folder references



知识共享许可协议 本站所有文章采用知识共享署名-非商业性使用-禁止演绎 3.0 中国大陆许可协议进行许可。
若未作说明,则本文为「热心人士」原创,转载需注明出处。
本文地址为:http://www.sunnyrx.com/2016/01/14/About-Undefined-symbols-for-architecture-x86-64-Error/