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