This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Need an ability to build standard DLLs with distutils
Type: enhancement Stage: resolved
Components: Build, ctypes, Documentation, Extension Modules, Windows Versions: Python 2.7
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Buraddin Ibn-Karlo, docs@python, iritkatriel, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2016-03-23 20:54 by Buraddin Ibn-Karlo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg262308 - (view) Author: Buraddin Ibn-Karlo (Buraddin Ibn-Karlo) Date: 2016-03-23 20:54
I want to make a a dynamic library to run its function with ctypes.

Also I want to build the library from sources with distutils (the C++ sources are distributed with my Python code).

But alas! Our distutils fails, if the library doesn't have initialization function (something like init_<module_name>). Even if the module does not need any initialization.

I did a quick and dirty solution: added a dummy function:
    void init_<module_name>(){}

It somehow works, but I don't think that it is a good idea.

Cannot you add the possibility to tell distutils, that this extention module is just a simple DLL, that will be used via ctypes (or somehow else) and it does not need any extra init script?

Also, cannot you add an extra section to ctypes documentation? With a description how to build such extensions via distutils?
msg262446 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-03-25 17:33
(Obligatory recommendation that you use Cython rather than ctypes, especially if you're going to require your users to have a compiler handy - in general this isn't recommended on Windows at all; make sure you distribute wheels if you want to make your users' lives easiest.)

I haven't tested this, but I believe you want to specify your libraries with the `libraries` parameter, not the `extensions` parameter:

    ('my_lib', {'sources': ['my_lib.c'], 'include_dirs': ['dirs', 'if', 'you', 'want'], 'macros': ['DEFINES', 'IF', 'YOU', 'WANT']})


Then you need to ensure build_clib is run to produce it. I'd imagine that will just happen, but I could be wrong.

Again, I haven't tried this myself, but it seems to be the right way to build a regular library.
msg262447 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-03-25 17:34
Oh, and just saw that you're apparently asking about 2.7. I was referring to the 3.5 sources for distutils, so some things may be different in 2.7. But I doubt distutils has changed that much since then.
msg392142 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-04-27 22:14
distutils is deprecated and python 2.7 is past EOL.
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70816
2021-04-27 22:14:21iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg392142

resolution: out of date
stage: resolved
2016-03-25 17:34:51steve.dowersetmessages: + msg262447
2016-03-25 17:33:56steve.dowersetmessages: + msg262446
2016-03-23 20:54:27Buraddin Ibn-Karlocreate