1

Here is the test.py file :

import numpy as np

def test(abc): # abc is numpy array
    c = np.sum(abc)
    return c

I tried converting it to test.pyx like this:

import numpy as np

cpdef public double test(abc): # abc is numpy array
    cdef double c = np.sum(abc)
    return c

using the command-line, I have successfully generated code: test.c, test.h

The command line used is: python setup.py build_ext --inplace

I have copied the include from the Python 3.7 folder and placed it in the same folder where my test.c and test.h are available.

Now I want to know how I can convert the .c file to .dll file after compilation?
I have seen these SO references:

Can Cython code be compiled to a dll so C++ application can call it?
Use generated header file from Cython
Using Cython to expose functionality to another application

But I am quite naive to understand this. Hence, I need help to understand how I can convert the .c to .dll.
Here is the test.c file: test.c and test.h

Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
  • Does this answer your question? [Can Cython code be compiled to a dll so C++ application can call it?](https://stackoverflow.com/questions/18515275/can-cython-code-be-compiled-to-a-dll-so-c-application-can-call-it) – ead Nov 24 '20 at 12:44
  • Please be more specific, what you don't understand in the duplicate target. Maybe starting with a simpler function and making it work would be a good starting point. Adding numpy arrays into the mix makes things more complicated. – ead Nov 24 '20 at 12:46
  • I have a very big module and this is the simplest example I have used. I know other example like adding two numbers will work. But the I have tried using the numpy. I have seen many examples related to the similar issue. But nothing is helpful when it comes to numpy. Hence, trying to get a solution for numpy. – Jaffer Wilson Nov 24 '20 at 12:49
  • I want to compile my code to dll. That's it. I want python to dll. – Jaffer Wilson Nov 24 '20 at 12:50
  • You need a compiler and a linker. there are plenty of resources on how to get source code to executables on various *OS*es. – CristiFati Nov 24 '20 at 14:59
  • @CristiFati May be. I have tried using gcc compiler but it is not working with the C code what Cython has developed. I am still trying to find a way. Hence, I have placed a query here on SO. – Jaffer Wilson Nov 24 '20 at 15:44
  • If you're using Windows it's much easier to use the version of MSVC that Python was built with (there's an official list of versions available). Your Numpy issues will be to do with setting the Python path I'd think - you won't end up with an entirely self-contained DLL so you'll still need to be able to import Numpy as before. – DavidW Nov 24 '20 at 21:55

0 Answers0