This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

How to make an extension of Python


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,
dllinit.c
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
CXXFLAGS = $(DEBUG)
CFLAGS = $(DEBUG)
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)

all: $(DLL_NAME) $(TESTPROGS)

#
# sources, objects, etc.
#
SRCS  = $(wildcard *.cc *.c)
OBJS  = $(SRCS:.cc=.o)
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.
DLL_CFLAGS = -DBUILDING_DLL=1
# The default entry point defined by dllwrap; the default user callback
# is DllMain, and there is stub in dllinit.c.
DLL_LDFLAGS =
# any extra libraries that your DLL may depend on.
DLL_LDLIBS = libpython2.0.a

DLL_SRCS  = myEnviron.c dllinit.c
DLL_OBJS  = $(DLL_SRCS:.cc=.o)
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)

$(DLL_NAME) $(DLL_EXP_DEF) $(DLL_EXP_LIB): $(DLL_OBJS)
 $(DLLWRAP) $(DLLWRAP_FLAGS) -o $(DLL_NAME) \
     $(DLL_OBJS) $(DLL_LDFLAGS) $(DLL_LDLIBS)

#
# 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.
#
.cc.o:
 $(CXX) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
.c.o:
 $(CC) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $<

----------=========---------
Mitsuo Igarashi
mitsu5@ruby.famille.ne.jp






--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]