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

时光毁灭记忆、已成空白 提交于 2019-12-13 13:10:14

问题


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?


回答1:


<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



回答2:


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



来源:https://stackoverflow.com/questions/12516830/mac-osx-10-7-4-xcode-4-4-1-no-array-header-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!