1

I am trying to compile a workspace of 3 projects with C++11 support. This set of projects has successfully compiled and linked using LLVM compiler defaults. In addition, the c++ code has previously compiled on a number of compilers including g++, llvm, msvc, sun, irix etc so it is very clean code.

Under the c++ language dialect section of the workspace build settings there are 3 line items:

c language dialect
c++ language dialect
c++ standard library

Using the settings:

c language dialect: compiler default
c++ language dialect: compiler default
c++ standard library: libc++ (LLVM c++ standard library with c++11 support)

I can successfully compile but get many link errors. Some are from our own functions and some are from standard functions. Here is a sample of link errors to standard functions:

(null): "std::string::find_last_of(char const*, unsigned long) const", referenced from: (null): "std::string::size() const", referenced from:

It seemed clear that I was linking to the wrong standard library, so I investigated changing various options above. Changing the dialect to -std=c++11 even broke my compilation. I could not find a combination that worked for me.

Can you suggest what might be wrong?

EDIT: my motivation for doing this is that I want to use std::thread in my c++ code that interfaces with objective-c (and have that c++ code still be portable)

2
  • I've been getting these kind of errors... [sorry i'll rephrase this as an answer..] meanwhile are you using latest Xcode and OSX? Commented Jan 10, 2013 at 3:48
  • I think this site explains this well. I am stuck on this recently and find it very helpful. Commented May 17, 2014 at 2:18

3 Answers 3

3

XCode 4.5.2 / OSX 10.8.2

I've been getting these

(null): "std::string::find_last_of(char const*, unsigned long) const", 
 referenced from: (null):    "std::string::size() const", referenced from:

Variously with different versions of openCV libraries. It seems like the issue is access to the C++ standard library. In this case working settings were as follows:

Older library versions:

C Language Dialect GNU99[-std=gnu99]
C++ Language Dialect GNU++11[-std=gnu++11]
C++ Standard Library libstdc++ (GNU C++ standard library)

recent library versions:

C Language Dialect GNU99[-std=gnu99]
C++ Language Dialect GNU++11[-std=gnu++11]
C++ Standard Library libc++ (LLVM C++ standard library with C++11 support)

Toggling the standard library spec to either version yields those errors.

Sign up to request clarification or add additional context in comments.

Comments

1

I finally traced the problem to two things

1) Despite the fact I set the compiler options at the workspace level, these options were not being propagated to the constituent projects. Something to be aware of! So in effect different projects were being compiled with different sets of compiler libraries and dialects - so not surprising there were link errors. The combination of options that worked for me were:

C Language Dialect Compiler Default
C++ Language Dialect -std=c++11
C++ Standard Library libc++ (LLVM C++ standard library with C++11 support)

2) Under c++11 compilation, one of my projects would not compile. After fixing the syntax error, it compiled and linked fine with the above options

Comments

1

While use Code 5 i had a similar problem

Undefined symbols for architecture armv7:
"std::string::clear()", referenced from:
FormatLog(unsigned int, int, char const*, std::string&) in libMO.a(AppLog.o)

Changing "Deployment Target" from 7.0 to 6.0 helped me.

For XCode 4.5 it seems have to use LLVM C++ with C++11 support compiler instead GNU C++ compiler for C++ Standard Library.

Comments

Your Answer

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