Tom Swirly Tom Swirly - 2 years ago 133
Python Question

Cython build can't find C++11 STL files - but only when called from

When I compile my code from, it can't find the C++11 include file

- but C++11 compiler features do work.

When I paste the same command line that generates into my shell, it all compiles perfectly well(!)

Code demonstrating this behavior can be seen here and is also pasted below.

Terminal session:

$ python build_ext
running build_ext
building 'simple' extension
creating build
creating build/temp.macosx-10.6-intel-3.4
/usr/bin/clang -fno-strict-aliasing -Werror=declaration-after-statement -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Isrc -I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c simple.cpp -o build/temp.macosx-10.6-intel-3.4/simple.o -Wno-unused-function -std=c++11
In file included from simple.cpp:289:
./simple.h:2:10: fatal error: 'array' file not found
#include <array>
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1

$ /usr/bin/clang -fno-strict-aliasing -Werror=declaration-after-statement -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Isrc -I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c simple.cpp -o build/temp.macosx-10.6-intel-3.4/simple.o -Wno-unused-function -std=c++11

# no error!

$ /usr/bin/clang --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

#!/usr/bin/env python3

import platform, distutils.core, distutils.extension, Cython.Build

EXTENSION = distutils.extension.Extension(
extra_compile_args=['-Wno-unused-function', '-std=c++11'],




cdef extern from "simple.h" namespace "fcolor4":
struct Simple:
int x


int foo() {
auto x = 1; // works, so must be C++11
return x;

#include <string> // works, so must find some STL.
#include <array> // fails!

Answer Source

I believe this is the same problem I was having before here. In my case, the problem seemed to be that setuptools was using the same compiler flags as when the Python interpreter was compiled, and these included a flag that made the code compatible with a rather old version of Mac OS X (which was far before C++11).

Try adding the flag -mmacosx-version-min=10.9 (or later) to extra_compile_args in your

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download