How to reliably find the C++11 <array> header?

Lawrence Velázquez larryv at macports.org
Fri Oct 31 10:04:47 PDT 2014


On Oct 31, 2014, at 5:45 AM, Thibaut Paumard <thibaut at macports.org> wrote:

> The error message is:
> /bin/sh ../libtool  --tag=CXX   --mode=compile /usr/bin/clang++
> -DHAVE_CONFIG_H -I. -I.. -I../include  -I../include
> -I/opt/local/include/udunits2/  -I/opt/local/include
> -DGYOTO_NO_DEPRECATED -D_THREAD_SAFE -pthread
> -DGYOTO_PREFIX=\"/opt/local\" -pipe -Os -arch x86_64 -stdlib=libstdc++
> -std=gnu++11 -MT Photon.lo -MD -MP -MF .deps/Photon.Tpo -c -o Photon.lo
> Photon.C
> In file included from Worldline.C:20:
> ../include/GyotoWorldline.h:36:11: fatal error: 'array' file not found
> # include <array>
> 
> I don't understand this as the <array> header is part of the C++11
> standard and the above command lines includes -std=gnu++11.

The command also specifies "-stdlib=libstdc++". Apple's libstdc++ does not support C++11.

% >foo.cc <<EOF
heredoc> #include <array>
heredoc> int main() {}
heredoc> EOF
% /usr/bin/clang++ -std=c++11 -stdlib=libc++ -o foo{,.cc}
% /usr/bin/clang++ -std=c++11 -stdlib=libstdc++ -o foo{,.cc}
foo.cc:1:10: fatal error: 'array' file not found
#include <array>
         ^
1 error generated.
%

The value of that flag is determined by ${configure.cxx_stdlib}, which defaults to "libstdc++" on Mountain Lion and older. As Josh said, you could set it to "libc++", but doing so is quite risky.

vq


More information about the macports-dev mailing list