简体   繁体   中英

Cython -std=c++11 error, using both C and C++

I'm new to Cython and I'm trying to compile Cython from this project without success.

With this setup.py,

from distutils.core import setup, Extension
from Cython.Distutils import build_ext
from distutils.extension import Extension

sources_list = ["timgraph.pyx", "Graph.cpp", "InfGraph.cpp", "sfmt/SFMT.c"]

setup(ext_modules=[Extension("pytim",
                             sources=sources_list,
                             language="c++",
                             extra_compile_args=["-std=c++11"])
                  ],
      cmdclass={'build_ext':build_ext})

I run the following:

python setup.py build_ext --inplace

and get the following error:

error: invalid argument '-std=c++11' not allowed with 'C/ObjC'
error: command 'clang' failed with exit status 1

I'm running macOS High Sierra 10.13.2, Python 3.6.2, Cython 0.27.3, and Apple LLVM version 9.0.0, in case any of that helps.

EDIT: I thought maybe it's from trying to compile both C and C++ simultaneously, because I can run the Cython example for C++ and it works fine. But I don't know how to get around the fact that the extra_compile_args applies to all of the sources, including "sfmt/SFMT.c".

Got the same issues with Python 3.7 and 3.6.5 and laters...

I got an error when I tried to run:

pip install python-crfsuite

That was derived from the setup.py file there...

The error:

error: invalid argument '-std=c99' not allowed with 'C++/ObjC++' 

The only thing that worked for me was to run it with Python 3.6.4

Go to here to install 3.6.4 and try again.

Or do it with Conda/Anaconda here

If you are facing issues with pkgs that you had on Python3.7 and you have mac try solving it with:

python location on mac osx

Just for the record, the solution was very simple: remove the extra_compile_args argument completely, but still set the language argument as c++ , ie

from distutils.core import setup, Extension
from Cython.Distutils import build_ext
from distutils.extension import Extension

sources_list = ["timgraph.pyx", "Graph.cpp", "InfGraph.cpp", "sfmt/SFMT.c"]

setup(ext_modules=[Extension("pytim",
                         sources=sources_list,
                         language="c++")
                   ],
      cmdclass={'build_ext':build_ext})

This for whatever reason successfully compiles both the C and the C++.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM