23

I am using third party frameworks in my native iOS application (bunch of .a libraries). My application is developed with XCode 5 base SDK 7.0.

The libraries compile and link fine when the deployment target is 6.1 (library and header search paths are good). However, when I change the deployment target to be 7.0, I get the following linker error:

Undefined symbols for architecture i386:
  "std::string::find_last_of(char const*, unsigned long) const", referenced from:
      GetExecutionDir(ECTemplateString<char>&, char*, bool) in myLibrary.a(moPlatForm.o)
  "std::string::find(char const*, unsigned long) const", referenced from:
      ParseLog(std::string const&, unsigned int&, CmoDateTime&, int&, std::string&) in myLibrary.a(AppLog.o)
  "std::string::size() const", referenced from:
      mo::CmoParam::WriteToStream(void*, mo::STREAM_STATE*) in myLibrary.a(moParams.o)
  "std::string::c_str() const", referenced from:
      GetExecutionDir(ECTemplateString<char>&, char*, bool) in myLibrary.a(moPlatForm.o)
      CMocaFileTransfer::UpdateParamsForGetTraceFiles(mo::CmoParamList&, long) in myLibrary.a(RobieFileTransfer.o)
      CMocaFileTransfer::AddTraceFileForUpload(std::string const&, std::string const&) in myLibrary.a(RobieFileTransfer.o)
      CMocaFileTransfer::CreateParamsForSendTraceFiles(mo::CmoObject&) in myLibrary.a(RobieFileTransfer.o)
      mo::CmoParam::WriteToStream(void*, mo::STREAM_STATE*) in myLibrary.a(moParams.o)
      ParseLog(std::string const&, unsigned int&, CmoDateTime&, int&, std::string&) in myLibrary.a(AppLog.o)
      CAppLog::LogExists(unsigned int) in myLibrary.a(AppLog.o)
      ...

Libraries are a bit old, I am not sure if there is a compatibility issue. I am not planning to support iOS 6 so I need to set the deployment target as 7.0. Any kind of help/direction would be great.

4
  • Any reason why these are getting compiled to i386? I'm guessing you need to remove i386 from the target build settings so only armv7 and armv7s is in there.
    – Daddy
    Oct 9, 2013 at 12:38
  • I have tried playing with the architectures. I don't think it is an architecture issue. By the way, libraries only support armv7, so armv7s is out of the question.
    – Guven
    Oct 9, 2013 at 12:40
  • I hear ya, but at the very top of the error it says architecture i386. Apparently it doesn't support that either :-)
    – Daddy
    Oct 9, 2013 at 12:53
  • Thanks for the hint. I am also facing the same kind of errors from trying to link to third party c++ libraries (libjingle). My environment is Xcode 5.0 and deployment target iOS 7.0. I just switched to deployment target iOS 6.1 for time being and the errors are gone. I guess for deployment target iOS 7.0, you need to add an empty .mm file (as mentioned in the below answers but I will try that later). Feb 4, 2014 at 7:08

3 Answers 3

46

for me, including the 'stdc++.6.0.9.dylib' instead of 'stdc++.dylib' into the dependencies resolved the linker errors too

5
  • That solved the problem. Thanks! What is the difference between these two libraries?
    – IPhone Guy
    Apr 13, 2014 at 0:13
  • I believe, that specifying a library directly, skips the Xcode logic for 'optimising' and checking if project contains C++ source files
    – Denis
    Apr 14, 2014 at 9:00
  • This solved the problem for me as well - without having to add any empty C++ files. Jan 5, 2015 at 17:32
  • Still an issue with Xcode 6.3.2, and this fix still works. Jun 23, 2015 at 14:29
  • what is about other linker flag what to set in that Feb 17, 2016 at 9:21
28

It turns out that if XCode can't find any C++ files in the project, then it assumes that libstd++ is not required. So, you have to manually add a C++ file to the project (an empty .mm file would be enough). That is the solution.

All the credits go to this answer in this Stackoverflow thread.

4
  • Voodoo stuff! Worked for me Jan 16, 2014 at 9:56
  • It also works if you add any C++ header #import to .pch file.
    – ETech
    Feb 6, 2014 at 14:06
  • 1
    Wow. This still is a problem in XCode 6.1.1 and this solution still works. Bananas. Thank you for putting the answer here too!
    – Kelly
    Dec 15, 2014 at 22:20
  • How to add this empty .mm file can you tell me ?? Feb 17, 2016 at 9:22
8

It looks as if myLibrary.a was built with calls to C++ code and used libstdc++ as its C++ standard library. Your application project probably specifies libc++ instead, perhaps as the compiler default.

Try switching back to libstdc++ and see if the errors go away (or change, at least). Your eventual solution is likely to be a library that's built against the new standard library.

1
  • Thanks for pointing this out but nope. This doesn't fix the issue. Actually, I remember getting errors from the library with the description 'libc++abi.dylib: handler threw exception'. So, I am guessing the library is compiled with libc++.
    – Guven
    Oct 9, 2013 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.