Last active
May 17, 2018 12:26
-
-
Save johntyree/4560948 to your computer and use it in GitHub Desktop.
C vs. C++ in Cython.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
# distutils: language = c++ | |
# distutils: sources = b.cpp | |
# Using C calling convention works with "cdef extern ..." directly; no | |
# hpp header. | |
# Without it we need to use the cdef extern from "b.hpp": ... declaration. | |
# Implicitly forces C calling convenction? | |
cdef extern void c() | |
# This works with C++ just fine. | |
cdef extern from "b.hpp": | |
void cpp_good() | |
# This doesn't. Undefined symbol 'cpp_bad'. | |
cdef extern void cpp_bad() | |
c() | |
cpp_good() | |
cpp_bad() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Indicate C calling convention for our C function. | |
extern "C" { void c(); } | |
void c() { } | |
void cpp_good() { } | |
void cpp_bad() { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void cpp_good(); | |
// If we include cpp_bad() here, we get an error about redefining it with C | |
// linkage after having already defined it with C++ linkage. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf8 | |
from setuptools import setup | |
from Cython.Build import cythonize | |
cython_modules = cythonize('*.pyx') | |
setup(ext_modules = cython_modules) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment