XCode: 'std::' link errors

27 October 2012

This is more of a reminder to myself about confusing linker errors that can appear in XCode when you are working on large projects with many dependencies.

Everything compiles just fine but when it comes to linking you get errors like this:

Undefined symbols for architecture i386:
  "TextureMan::LoadTexture(std::__1::basic_string, std::__1::allocator > const&, int, bool)", referenced from:
      tolua_gameinterface_TextureMan_loadTexture00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
  "SoundManager::BgndMusicPlay(std::__1::basic_string, std::__1::allocator > const&, bool)", referenced from:
      tolua_gameinterface_SoundManager_BgndMusicPlay00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
  "SoundManager::BgndMusicStop(std::__1::basic_string, std::__1::allocator > const&, bool)", referenced from:
      tolua_gameinterface_SoundManager_BgndMusicStop00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
  "Font::LoadFont(std::__1::basic_string, std::__1::allocator > const&)", referenced from:
      tolua_gameinterface_Font_loadFont00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
  "System::MakeDocumentPath(std::__1::basic_string, std::__1::allocator > const&) const", referenced from:
      tolua_gameinterface_System_makeDocumentPath00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
  "System::MakeResourcePath(std::__1::basic_string, std::__1::allocator > const&) const", referenced from:
      ExUnit::LogicThread::Run() in libCoreClientiOS.a(logicthread.o)
      tolua_gameinterface_System_makeResourcePath00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
  "std::__1::__vector_base_common::__throw_length_error() const", referenced from:
      void std::__1::vector >::__push_back_slow_path(float const&&&) in libCoreClientiOS.a(tolua_gameinterface.o)
      void std::__1::vector, std::__1::allocator > >::__push_back_slow_path const&>(std::__1::basic_string, std::__1::allocator > const&&&) in libCoreClientiOS.a(tolua_gameinterface.o)
      void std::__1::vector >::__push_back_slow_path(int const&&&) in libCoreClientiOS.a(tolua_gameinterface.o)
  "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
      std::__1::basic_ostream >& std::__1::endl >(std::__1::basic_ostream >&) in libCoreClientiOS.a(logicthread.o)
  "std::__1::ios_base::getloc() const", referenced from:
      std::__1::basic_ostream >& std::__1::endl >(std::__1::basic_ostream >&) in libCoreClientiOS.a(logicthread.o)
  "std::__1::basic_string, std::__1::allocator >::__init(char const*, unsigned long)", referenced from:
      _l_registercallback in libCoreClientiOS.a(logicthread.o)
      _luapanic in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::Run() in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::HandleError() in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::CallVA(char const*, char const*, ...) in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::RemoveCallback(char const*) in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::SetCallback(char const*, int) in libCoreClientiOS.a(logicthread.o)
      ...
  "std::__1::basic_string, std::__1::allocator >::assign(char const*)", referenced from:
      System::SetEngineScriptPath(char const*) in libCoreClientiOS.a(tolua_gameinterface.o)
  "std::__1::basic_string, std::__1::allocator >::basic_string(std::__1::basic_string, std::__1::allocator > const&)", referenced from:
      tolua_gameinterface_vector_string___geti00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
      tolua_gameinterface_vector_string___geti01(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
      tolua_gameinterface_vector_string__push_back00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
      void std::__1::vector, std::__1::allocator > >::__push_back_slow_path const&>(std::__1::basic_string, std::__1::allocator > const&&&) in libCoreClientiOS.a(tolua_gameinterface.o)
  "std::__1::basic_string, std::__1::allocator >::~basic_string()", referenced from:
      _l_registercallback in libCoreClientiOS.a(logicthread.o)
      _luapanic in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::Run() in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::HandleError() in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::CallVA(char const*, char const*, ...) in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::RemoveCallback(char const*) in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::SetCallback(char const*, int) in libCoreClientiOS.a(logicthread.o)
      ...
  "std::__1::basic_string, std::__1::allocator >::operator=(std::__1::basic_string, std::__1::allocator > const&)", referenced from:
      tolua_gameinterface_vector_string___seti00(lua_State*) in libCoreClientiOS.a(tolua_gameinterface.o)
  "std::__1::basic_ostream >::put(char)", referenced from:
      std::__1::basic_ostream >& std::__1::endl >(std::__1::basic_ostream >&) in libCoreClientiOS.a(logicthread.o)
  "std::__1::basic_ostream >::flush()", referenced from:
      std::__1::basic_ostream >& std::__1::endl >(std::__1::basic_ostream >&) in libCoreClientiOS.a(logicthread.o)
  "std::__1::basic_ostream >::sentry::sentry(std::__1::basic_ostream >&)", referenced from:
      std::__1::basic_ostream >& std::__1::operator<<<std::__1::char_traits >(std::__1::basic_ostream >&, char const*) in libCoreClientiOS.a(logicthread.o)
  "std::__1::basic_ostream >::sentry::~sentry()", referenced from:
      std::__1::basic_ostream >& std::__1::operator<<<std::__1::char_traits >(std::__1::basic_ostream >&, char const*) in libCoreClientiOS.a(logicthread.o)
  "std::__1::cerr", referenced from:
      ExUnit::LogicThread::Run() in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::ContactTriggered(b2Contact*) in libCoreClientiOS.a(logicthread.o)
      ExUnit::LogicThread::SensorTriggered(b2Contact*) in libCoreClientiOS.a(logicthread.o)
  "std::__1::ctype::id", referenced from:
      std::__1::basic_ostream >& std::__1::endl >(std::__1::basic_ostream >&) in libCoreClientiOS.a(logicthread.o)
  "std::__1::locale::~locale()", referenced from:
      std::__1::basic_ostream >& std::__1::endl >(std::__1::basic_ostream >&) in libCoreClientiOS.a(logicthread.o)
  "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
      std::__1::basic_ostream >& std::__1::operator<<<std::__1::char_traits >(std::__1::basic_ostream >&, char const*) in libCoreClientiOS.a(logicthread.o)
  "std::__1::ios_base::clear(unsigned int)", referenced from:
      std::__1::basic_ostream >& std::__1::operator<<<std::__1::char_traits >(std::__1::basic_ostream >&, char const*) in libCoreClientiOS.a(logicthread.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This looks really confusing. How can there be link errors for STL classes, aren't they all templates?... and shouldn't the compiler have just compiled all that junk and everything should be all fine and dandy. Well it turns out, as with everything in c++, things aren't that simple.

Your code is dependant on the C++ Standard Library and there is a good chance you are compiling against different versions of the C++ Standard Library. To fix this you need to open up your target options in xcode and make sure that the C++ Langiage Dialect and C++ Standard Library are set the same (compiler default is usually good enough) FOR ALL dependant projects. If it's not the same for all, you'll see the mess above.

Hope that helps someone,

dazza

comments powered by Disqus