Cythonize a simple C DLL (without a lib file)

407 views
Skip to first unread message

Idan Miara

unread,
May 19, 2021, 8:57:17 AM5/19/21
to cython-users
Hi,

I am tying to Cythonize a 3rd party DLL with a C API. I don't have a lib file for it.

To simplify, I've created the following example with a single `add` function.
I've compiled addlib.cpp with the command line:
`cl.exe /D ADDLIB_EXPORTS addlib.cpp /link /DLL /OUT:addlib.dll`
Then I've deleted the cpp file and ran setup.py:
`python setup.py build_ext --inplace`
It compiles and builds successfully using the lib file and `addlib_test.py` does work. 
How can I do the same without the lib file ?

Best regards,
Idan

Stefan Behnel

unread,
May 19, 2021, 10:37:48 AM5/19/21
to cython...@googlegroups.com
Hi!

Idan Miara schrieb am 19.05.21 um 14:29:
It's a common gotcha with Cython that new users give their C/C++ code file
the same name as their .pyx file, and then Cython overwrites the .cpp file
when it translates the .pyx file. Give both different names. Then you can
simply add the .cpp file as additional source file in your setup.py.

Stefan

Idan Miara

unread,
May 19, 2021, 10:48:20 AM5/19/21
to cython...@googlegroups.com
Hi Stefan, 

Thanks for your prompt reply! 
I understand your point, but my actual use case is a closed source dll+h file, so no cpp or lib files. 

I gave that example just to simplify and give an actual example. 

Any pointers on how to Cythonize it? 

--

---
You received this message because you are subscribed to a topic in the Google Groups "cython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cython-users/aohtQnI2NTM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cython-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/ef39fb51-4da7-db7c-2e40-b0a6a9e28ace%40behnel.de.

Idan Miara

unread,
May 19, 2021, 1:47:51 PM5/19/21
to cython...@googlegroups.com
Hi all,

I've found a solution - it is possible to create a lib file (import library) from a dll file:
I've created a batch file to automate it, feel free to use it.

Idan

bactone li

unread,
Apr 28, 2023, 1:07:07 AM4/28/23
to cython-users
have you find the solution, I have same question

Idan Miara

unread,
Apr 28, 2023, 7:28:20 AM4/28/23
to cython...@googlegroups.com
Hi,
It has been a long time, but this is what I found back then:

I've found a solution - it is possible to create a lib file (import library) from a dll file:
I've created a batch file to automate it, feel free to use it.


Idan
Reply all
Reply to author
Forward
0 new messages