Jefferson Hudson
Jefferson Hudson

Reputation: 738

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?

Upvotes: 6

Views: 5973

Answers (2)

justin
justin

Reputation: 104698

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).

Upvotes: 5

kennytm
kennytm

Reputation: 523614

<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

Upvotes: 5

Related Questions