I developed some classes in Visual Studio 2012 which make heavy use of C++11 features and also uses new std features like threads and mutex. The reason was to be platform independent. Trying to port the code to OSX the Xcode compiler 5.0 cannot open following includes:
#include <chrono>
#include <thread>
#include <functional>
#include <mutex>
I already switch the build settings to C++11 and searched the usr/include path for the includes. Please do not suggest boost as I try to eliminate it from my projects.
You need both -std=c++11
and -stdlib=libc++
:
$ cat cpptest.cpp
#include <chrono>
#include <thread>
#include <functional>
#include <mutex>
int main() {
return 0;
}
$ clang -o cpptest -std=c++11 -stdlib=libc++ cpptest.cpp
$ echo $?
0
Give that you're using Xcode, you shouldn't need to specify explicit flags to clang
or add build paths to /usr/include
, as that is done for you by the IDE. What you need to do is open the project settings -> Build Settings and set C++ Language Dialect to C++11 and the C++ Standard Library to libc++ (LLVM C++ standard library with C++11 support)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With