1

I'm stuck trying to use unordered_sets in Cython in a Jupyter Notebook on my Mac.

%%cython -a -3
# distutils: language = c++
# cython: c_string_type=unicode, c_string_encoding=utf8
import cython
from libcpp.unordered_set cimport unordered_set

def test():
    cdef unordered_set[int] s
    return s

The above cell throws: DistutilsExecError: command 'gcc' failed with exit status 1

user666
  • 5,231
  • 2
  • 26
  • 35
  • 1
    If you look at the terminal window you started jupyter from, the gcc output should be there? FWIW this works fine on Windows with Visual C++ – chrisb Jan 03 '19 at 21:25

2 Answers2

2

Older gcc versions don't use c++-11 (but c++-98) per default, and because unordered_map is a c++11-feature, you need to pass the option to the compiler.

For example via:

%%cython -a -3 -c=-std=c++11

Or update your gcc to 6.0 or above.

ead
  • 32,758
  • 6
  • 90
  • 153
0

What finally worked for me was a modified version of @ead's answer.

I updated GCC using homebrew (and XCode), and the following code does not throw the same error as before.

%%cython -a -3 -c=-stdlib=libc++
# distutils: language = c++

import cython
from libcpp.unordered_set cimport unordered_set

def test():
    cdef unordered_set[int] s
    return s
user666
  • 5,231
  • 2
  • 26
  • 35