0

I'm using python 3.4 and I'm going to be wrapping some cpp files that use some of the new c++ language features along with openmp, however, I'm having some trouble getting it to work. I've installed gcc5 using brew and I can compile my cpp files just fine. When I try to wrap them into pyx files, I get compiler errors. Here is my setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import os

os.environ["CC"] = "/usr/local/Cellar/gcc/5.2.0/bin/g++-5"
os.environ["CXX"] = "/usr/local/Cellar/gcc/5.2.0/bin/g++-5"

modules = [Extension("constellation",
                     ["constellation.pyx"],
                     language="c++",
                     extra_compile_args=["-std=c++1y"])]

for e in modules:
    e.cython_directives = {"embedsignature": True}

setup(name="constellation",
      cmdclass={"build_ext": build_ext},
      ext_modules=modules)

Running

python3 setup.py build_ext --inplace

I get a ton of these errors:

cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
/var/folders/33/vsltc7m51l77bd5qlw3bwxzm0000gn/T//ccuePcPk.s:39:bad register name `%rdi)'
/var/folders/33/vsltc7m51l77bd5qlw3bwxzm0000gn/T//ccuePcPk.s:40:bad register name `%rdi)'
/var/folders/33/vsltc7m51l77bd5qlw3bwxzm0000gn/T//ccuePcPk.s:41:bad register name `%rdi)'
/var/folders/33/vsltc7m51l77bd5qlw3bwxzm0000gn/T//ccuePcPk.s:101:bad register name `%rbx'
...
/var/folders/33/vsltc7m51l77bd5qlw3bwxzm0000gn/T//cca3Gn0U.s:15821:Rest of line ignored. 1st junk character valued 64 (@).
error: command '/usr/local/Cellar/gcc/5.2.0/bin/g++-5' failed with exit status 1

If I change the compiler to the normal g++, it works fine and compiles with Apple LLVM version 6.1.0 (clang-602.0.53)

Does anyone know what's happening? Would it be better to build a static or dynamic library and wrap that instead? If you can't tell, I'm pretty new to Cython. Any advice is greatly appreciated!

uclatommy
  • 305
  • 4
  • 11

1 Answers1

1

I managed to get it to compile. Here's my setup.py in case it helps anyone having the same problems:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import os

os.environ["CC"]= "/usr/local/Cellar/gcc/5.2.0/bin/g++-5"
os.environ["CXX"]= "/usr/local/Cellar/gcc/5.2.0/bin/g++-5"
os.environ["MACOSX_DEPLOYMENT_TARGET"]= "10.10"
os.environ["ARCHFLAGS"]= "-arch x86_64"
os.environ["CFLAGS"]= (
    '-I/Users/Thomas/Documents/workspace/Quantum/Symengine '
    '-I/Users/Thomas/Documents/workspace/Quantum/Symengine/symengine '
    '-I/Users/Thomas/Documents/workspace/Quantum/Symengine/symengine/teuchos '
    '-I/Users/Thomas/Documents/workspace/Quantum/SymCell '
    '-I/Users/Thomas/googletest/googletest/include '
    '-I/Users/Thomas/Documents/workspace/Quantum/QuantumCell '
    '\"-I/Users/Thomas/Documents/workspace/Quantum/Quantum CPP\" '
)

extensions = [
    Extension("constellation",
        sources=["constellation.pyx"],
        language="c++",
        extra_compile_args=["-std=c++1y","-fopenmp"],
        extra_link_args=["-fopenmp"])]

setup(
    name = "constellation",
    ext_modules = cythonize(extensions)
)

Looks like my cython isn't properly setup and I needed to manually set some of the environment variables. In particular, the compiler was adding -arch i386 for some reason. Explicitly setting the ARCHFLAGS gets rid of it. It also looks like I'll be able to use openmp in the c++ code as well, which is great! Crossing my fingers...

uclatommy
  • 305
  • 4
  • 11