How to make an extension of Python

Mitsuo Igarashi
Thu Nov 2 22:41:00 GMT 2000

This is a question.of a newbie.

I am trying to make an extension of Python-2.0 in Cygwin 1.1.4
on Windows98 for my trainig.

As a sample of the extension, I am borrowing a file "environ.c" from the
book "Programming Python by Mark Lutz published by O'Reilly &
Associates, Inc" in page 54.

To create an extension, I follow the example of "DllHelpers-0.25
by Mumit Khan". Among the files of the DllHelpers-0.25,  I use cdll.h,
and Makefile in addition to "environ.c (renamed as myEnviron.c)".
The Makefile is changed as follows.

Created myEnviron.pyd is imported in Python.Then I get the message:
"Importerror: dynamic modules doese not define init
function ( initmyEnviron)".

I try another comiling way.
I make a def file manually "EXPORTS   initmyEnviron".
Wth the already formed myEnviron.o, I compile as follows:

dllwrap -o myEnviron.pyd -def myEnviron.def myEnviron.o -lpython2.0

I get the same error message.

Anyone, please teach me how to manage.

The changed Makefile(DllHelpers-0.25 by Mumit Khan):::::
# Makefile for Cygwin.
CC = gcc
CXX = c++

DEBUG = -g -Wall #-O2
CPPFLAGS = -I/usr/local/include/python2.0

AS = as
DLLTOOL = dlltool
DLLWRAP = dllwrap

#exeext = .exe

# Various targets to build.
DLL_NAME = myEnviron.pyd
DLL_EXP_LIB = libmyEnviron.a
DLL_EXP_DEF = myEnviron.def

#TESTPROGS = usedll$(exeext)


# sources, objects, etc.
SRCS  = $(wildcard *.cc *.c)
OBJS  = $(
OBJS := $(OBJS:.c=.o)

# DLL related variables. These are used when building the DLL. See later.

# Must define BUILDING_DLL when building the DLL. Otherwise import/exports
# will not work correctly. See dllclass.h for more info.
# The default entry point defined by dllwrap; the default user callback
# is DllMain, and there is stub in dllinit.c.
# any extra libraries that your DLL may depend on.
DLL_LDLIBS = libpython2.0.a

DLL_SRCS  = myEnviron.c dllinit.c
DLL_OBJS  = $(
DLL_OBJS := $(DLL_OBJS:.c=.o)

# Making DLL

# Note that we let dllwrap create both the DEF and IMPORT library in
# one shot. No need to run dlltool anymore.
DLLWRAP_FLAGS = --export-all --output-def $(DLL_EXP_DEF) \
 --implib $(DLL_EXP_LIB) \
 --driver-name $(CC)


# dependencies.

$(OBJS): cdll.h
myEnviron.o: myEnviron.c
dllinit.o: dllinit.c
#usedll.o: usedll.c

# default rules for building DLL objects. Note that client programs (ie.,
# the ones that *use* the DLL) have to be compiled without the DLL_CFLAGS
# flags.
 $(CXX) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
 $(CC) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $<

Mitsuo Igarashi

Want to unsubscribe from this list?
Send a message to

More information about the Cygwin mailing list