You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Built with python setup.py build_ext --inplace or python setup.py build_ext -i, tested with python main.py. The code compiles and presents the string in the terminal, but if the lines defining myfun in cpp_hello.pyx are removed, it fails to compile:
[1/1] Cythonizing cpp_hello.pyx
running build_ext
building 'cpp_hello' extension
creating build
creating build/temp.linux-x86_64-cpython-310
x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/usr/include/python3.10 -c cpp_hello.cpp -o build/temp.linux-x86_64-cpython-310/cpp_hello.o
cpp_hello.cpp: In function ‘int __pyx_pymod_exec_cpp_hello(PyObject*)’:
cpp_hello.cpp:3027:84: error: ‘hello_from_cpp’ was not declared in this scope
3027 | PyObject* wrapped = __Pyx_CFunc_9cpp_hello_void__lParen__rParennoexcept_to_py_(hello_from_cpp);
| ^~~~~~~~~~~~~~
cpp_hello.cpp: At global scope:
cpp_hello.cpp:2362:18: warning: ‘PyObject* __Pyx_CFunc_9cpp_hello_void__lParen__rParennoexcept_to_py_(void (*)())’ defined but not used [-Wunused-function]
2362 | static PyObject *__Pyx_CFunc_9cpp_hello_void__lParen__rParennoexcept_to_py_(void (*__pyx_v_f)(void)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
Expected behaviour
I should be able to expose the C++ function to Python using cpdef extern void hello_from_cpp() without requiring additional code.
OS
Linux/WSL2
Python version
3.10.12
Cython version
3.0.10
Additional context
I also tried the alternative declaration cdef extern from "hello.cpp", but I can't create a homonimous function hello_from_cpp() as I wish.
The text was updated successfully, but these errors were encountered:
Describe the bug
This started as a Stack Overflow question and was pointed to be a possible bug.
Code to reproduce the behaviour:
hello.cpp
cpp_hello.pyx
setup.py
main.py
Built with
python setup.py build_ext --inplace
orpython setup.py build_ext -i
, tested withpython main.py
. The code compiles and presents the string in the terminal, but if the lines definingmyfun
incpp_hello.pyx
are removed, it fails to compile:Expected behaviour
I should be able to expose the C++ function to Python using
cpdef extern void hello_from_cpp()
without requiring additional code.OS
Linux/WSL2
Python version
3.10.12
Cython version
3.0.10
Additional context
I also tried the alternative declaration
cdef extern from "hello.cpp"
, but I can't create a homonimous functionhello_from_cpp()
as I wish.The text was updated successfully, but these errors were encountered: