This is the mail archive of the cygwin@cygwin.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]

Problem linking python extensions


Hi,

I had thought that once I got my python extension to compile, my
troubles would be few ...

My extension does indeed compile, but I must not be building the dll
correctly, because python can't seem to find the entry point.  First,
here are the error messages:

When my dll is named TermObject.dll, I get:

Python 2.1.1 (#2, Aug 23 2001, 10:41:44)
[GCC 2.95.3-5 (cygwin special)] on cygwin
...
>>> import TermObject
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function
(initTermObject)

When my dll is named TermObject.pyd, I get:

>>> import TermObject
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named TermObject

In both cases, nm shows that TermObject.dll (or pyd) contains the line:
00402238 T _initTermObject

The .defs file produced by dlltool looks like:
; dlltool --base-file TermObject.base --output-def TermObject.def
--output-exp TermObject.exp --dllname TermObject.dll
EXPORTS

which, to me, looks like nothing is getting exported.

The code looks like:

DL_EXPORT(void) initTermObject(HANDLE h, DWORD reason, void *foo)
{
  Py_InitModule("TermObject", TermObjectMethods);
  import_array();
}

The makefile (which I got from the Cygwin user's guide) looks like:

  $(CC) -s -Wl,--base-file,TermObject.base -o TermObject.dll
TermObject.o -Wl,-e,_initTermObject $(LDLIBS)
  $(DLLTOOL) --base-file TermObject.base --output-def TermObject.def
--output-exp TermObject.exp --dllname TermObject.dll
  $(CC) -s -Wl,--base-file,TermObject.base,TermObject.exp -o
TermObject.dll TermObject.o -Wl,-e,_initTermObject $(LDLIBS)
  $(DLLTOOL) --base-file TermObject.base --output-def TermObject.def
--output-exp TermObject.exp --dllname TermObject.dll
  $(CC) -Wl,TermObject.exp -o TermObject.dll TermObject.o
-Wl,-e,_initTermObject $(LDLIBS)

Note that in the user's guide, _initTermObject is rendered
_initTermObject@12, but the need for the @12 part seems to go away with
the use of DL_EXPORT(void).  I've tried it both ways.

If I add the line:

  $(DLLTOOL) --output-def TermObject.def --dllname TermObject.dll
--output-lib TermObject.dll

I get the error message:

>>> import TermObject
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dlopen: Win32 error 193

I have also tried a whole bunch of other permutations including using
"int WINAPI", as suggested by the Cygwin user's guide, or
"__declspec(dllexport)", as is done with windows apps, instead of
"DL_EXPORT(void)" in my C code.  If I try to follow the dlltool manpage
and use asm directives, I wind up creating something that causes python
to coredump.

Any help is greatly appreciated.

Thanks.

Darrell



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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