- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What do I need to do to get something like this to compile on Mac OS X?
#include
#include
int main(int argc, char * argv[]) {
std::unique_ptr aUniqueNumber(new int);
*aUniqueNumber = 42;
std::cout << "Has anyone thought about this number " <<< " before?" << std::endl;
return 0;
}
I have managed to find the -std=c++0x flag but failed to get the compiler to pick up the right version of the standard libraries.
Apologies for any newbie mistakes in formatting or not finding answers that are readily available elsewhere.
Thanks,
Martin
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What error are you seeing?
What version of g++ is installed on your system (do a g++ -v)?
Our compileruses the standard libraries installed on the operating system and older versions of g++ (older than version 4.4)do not have support for C++11.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Compiling the above gives the error
error: namespace "std" has no member "unique_ptr"
so the compiler has clearly not found a C++11 compliant version of the standard library.
The system version of g++ is 4.2.1 as tweaked by Apple and they are not likely to ever ship a newer version of g++. They are commited to clang/llvm and would get into trouble with the GPL3 license if they adapted and shipped the current version of g++.
I have g++ version 4.6 installed, and clang does also have C++11 versions of the standard library.
Thanks,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another alternative might be to use Boost* or a similar third party C++ library that supports C++11. The Intel compiler mostly relies on the native library for runtime support - we only provide specific runtime support ourselves where we think we can add performance like with math functions or memory routines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
After some frustration I think it is fair to say that it is not possible to get the Intel C++ compiler to work with either the LLVM libc++ libraries or boost. I were to advise Intel I would recommend you to try to get your compiler to work together with LLVM libc++ libraries, it would surprise me if that does not give a significant increase in the number of Mac OS X developers that are prepared to pay for your software.
In the end what I had to do was to install g++ 4.5, with macports installed the command is
sudo port install gcc45
If you are compiling from the command line you can now compile with GCC 4.5 libraries like this
icc -gxx-name=/opt/local/bin/g++-mp-4.5 -std=c++0x foo.cpp
To compile from Xcode we need to make sure that icc can find g++-mp-4.5 from a directory that is in the developer environment path. There are surely more than one way to do this, but I succeeded by adding a soft link
/Developer/usr/bin.
cd /Developer/usr/bin
ln -s /opt/local/bin/g++-mp-4.5 .
In the Xcode project, make sure that that ANSI C Conformance flag is set to "Accept ANSI ISO C++0X extensions". Add -gxx-name=g++-mp-4.5 to the additional c++ flags.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page