Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OSX 10.7.4, Xcode 4.4.1, no <array> header file?

I am writing a program that will use the array container of the C++ Standard Library to hold some objects. However, whenever I try to include the following line of code in my program:

#include <array>

I receive the following error at compile time:

75-143-76-177:soft jeffersonhudson$ g++ mms.cpp -o mms
mms.cpp:5:17: error: array: No such file or directory 
75-143-76-177:soft jeffersonhudson$ 

Commenting out the #include lets me compile just fine. Surely I am overlooking something simple? I have installed the "Command Line Tools" in Xcode, am I still missing something?

EDIT:

I have found the location of array on my computer

/usr/clang-ide/lib/c++/v1

knowing that, what should I do?

like image 394
Jefferson Hudson Avatar asked Sep 20 '12 16:09

Jefferson Hudson


2 Answers

<array> is provided in C++11, you need to provide the -std=c++11 flag to enable it, and provide the -stdlib=libc++ flag for the corresponding library. But the g++ provided by Xcode is so old which doesn't have much support for C++11. Could you switch to clang?

clang++ -std=c++11 -stdlib=libc++ mms.cpp -o mms
like image 66
kennytm Avatar answered Oct 23 '22 00:10

kennytm


from the looks of it, you are not using LLVM's libc++, but GCC's libstdc++.

to use std::array in the latter context, use:

#include <tr1/array>

if you want to use libc++ and C++11, then alter your compiler flags as KennyTM suggested (+1).

like image 36
justin Avatar answered Oct 23 '22 01:10

justin