I have a toy project that's implemented as a C++ library and exposed to Python using a Cython wrapper. After not touching the project for a few months, I tried to build it from scratch today and got the following error.
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/standage/anaconda3/include -arch x86_64 -I/Users/standage/anaconda3/include -arch x86_64 -Iinc/ -I/Users/standage/anaconda3/include/python3.6m -c contra.cpp -o build/temp.macosx-10.7-x86_64-3.6/contra.o --std=c++11 -Wno-unused-function
In file included from contra.cpp:506:
In file included from inc/bstree.hpp:13:
inc/node.hpp:20:14: error: no template named 'unique_ptr' in namespace 'std'
std::unique_ptr< node<Data> > left;
~~~~~^
inc/node.hpp:21:14: error: no template named 'unique_ptr' in namespace 'std'
std::unique_ptr< node<Data> > right;
~~~~~^
In file included from contra.cpp:506:
inc/bstree.hpp:35:22: error: no template named 'unique_ptr' in namespace 'std'
typedef std::unique_ptr< node<Data> > nodeptr;
~~~~~^
inc/bstree.hpp:22:20: error: cannot initialize a member subobject of type 'contra_cpp::bstree::nodeptr' (aka 'int') with an rvalue
of type 'nullptr_t'
bstree() : _root(nullptr), _count(0) {}
^ ~~~~~~~
4 errors generated.
error: command 'gcc' failed with exit status 1
The error refers to this code below (see here for full context).
#include <memory>
namespace contra_cpp
{
template<typename Data>
class node
{
public:
std::unique_ptr< node<Data> > left;
std::unique_ptr< node<Data> > right;
Data data;
int height;
node<Data>(Data value)
: left(nullptr), right(nullptr), data(value), height(-1) {}
node<Data>(Data value, int ht)
: left(nullptr), right(nullptr), data(value), height(ht) {}
};
} // namespace contra_cpp
There is no error when I compile the C++ code alone, or when I build the Python extension (python setup.py install
) on Ubuntu 16.04. The error only appears when I attempt to build the extension on Mac (10.13.4).
My first thought is that the <memory>
library isn't being loaded properly, but it seems to be #include
-d fine. What could be causing this error?
UPDATE
C++11 support is certainly turned on when compiling. I have the following in my setup.py
file...
contra = Extension(
'contra',
sources=cythons + sources,
include_dirs=['inc/'],
language='c++',
extra_compile_args=['--std=c++11', '-Wno-unused-function'],
extra_link_args=['--std=c++11'],
)
...and you can see the --std=c++11
flag being included correctly in the original snippet above.