Subject: Re: [SciPy-dev] SciPy on Cygwin
From: Jason Tishler <[email-masked]>
To: Jochen Küpper <[email-masked]>
Cc: Jochen Küpper <[email-masked]>, Cygwin <[email-masked]>
Date: Fri, 28 Sep 2001 13:57:00 -0400

Jochen,

On Fri, Sep 28, 2001 at 10:48:13AM -0400, Jochen Küpper wrote:
> A little further, but now I am having linking problems. See end of
> message for current problem:

Note that you never really gave enough context (at least on the Cygwin
list) for people to help you.  So the following is my best WAG...

> >>>>> Jason Tishler wrote on Thu, 27 Sep 2001 16:48:48 -0400:
> 
> Jason> The usually solution to the above kind of errors is the
> Jason> following:
> 
> Jason> http://www.python.org/doc/FAQ.html#3.24
> 
> Jason> Unfortunately, the above line does *not* seem to jib with this solution.
> 
> Right. And compiling with g++ reveals a ton of other errors.

No, I meant change the code as explained by the above URL not compile
with g++.

> >>>>> Travis Oliphant wrote on Thu, 27 Sep 2001 11:19:26 -0600 (MDT):
> 
> Travis> Well it looks like some more ifdefs are needed.
> 
> Travis> I think there is some DL_EXPORT macro that needs to be used somewhere for
> Travis> it to work on CYGWIN.  Because this is an f2py generated file, I'm not
> Travis> sure what to do.  Does f2py support Cygwin?
> 
> I actually tried to put DL_EXPORT macros at different position, but
> since I pretty clueless about both Cygwin and python C-extensions I
> don't have too much of an understanding where it has to go:(

The following are the "tricks" for building Cygwin Python extensions:

    o DL_EXPORT is typically only need for the extension's init function
    o -DUSE_DL_IMPORT needs to be supplied during compilation
    o Cygwin Python's import library (e.g. libpython2.1.dll.a) needs to
      be supplied during linking

> >>>>> Pearu Peterson wrote on Thu, 27 Sep 2001 20:10:57 +0200 (EET):
> 
> Pearu> I have never tried cygwin but it is basically gcc (right?) and therefore
> Pearu> I did not see any reasons why f2py generated code would fail on
> Pearu> cygwin. However, it seems that I need to let f2py to put lines like 477
> Pearu> above to init<module> () block. But if there is a way to use macros please
> Pearu> let me know - the fix will be certainly simpler for me.
> 
> Pearu> Meanwhile I suggest manually moving the initializations with Py_None to
> Pearu> the function flapackmodule(). (I am not sure when I am able to fix f2py
> Pearu> as it will not be trivial).
> 
> >>>>> Pearu Peterson wrote on Thu, 27 Sep 2001 20:16:32 +0200 (EET):
> Pearu> I meant to the function initflapack().

The above seems to be congruent with the above mentioned Python FAQ URL.

> Well, that could be a solution for me since it isn't too much work,

Agreed.

> a appropriate putch could probable even be applied by setup.py?

Huh?

> Running into the next problem is the definition of PyFortran_Type in
> fortranmodule.h, I changed in the following way:
> 
> - no global initialization:
> 
> PyTypeObject PyFortran_Type;
> 
> - created this function in fortranmodule.c, added declaration to
> fortranmodule.h and call it from initflapack:
> 
> void fortranobject_init(void) {
>   PyFortran_Type = (PyTypeObject){
>     PyObject_HEAD_INIT(&PyType_Type)
>     0,			/*ob_size*/
> [snip]
>     (ternaryfunc)fortran_call,                    /*tp_call*/
>   };
> }
> 
> Does this look like a reasonable idea?

No, I would structure the code as suggested by the above mentioned
Python FAQ URL.  You can also look at the standard Python extensions in
Modules directory of the Python source tree for examples.

> Well, it compiles, but I get undefined references on linking.
> 
> > gcc -shared -Wl,--enable-auto-image-base
> build/temp.cygwin-1.3.3-i686-2.1/flapackmodule.o
> build/temp.cygwin-1.3.3-i686-2.1/fortranobject.o -L/usr/local/lib
> -L/usr/lib/python2.1/config -L/usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5
> -L/usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5
> -Lbuild/temp.cygwin-1.3.3-i686-2.1 -Lbuild/temp.cygwin-1.3.3-i686-2.1
> -llapack -lcblas -lf77blas -latlas -lpython2.1 -lamos -ltoms -lfitpack
> -lminpack -lquadpack -lodepack -llinpack_lite -lmach -lg2c -lgcc
> -lc_misc -lcephes -o
> build/lib.cygwin-1.3.3-i686-2.1/scipy/linalg/flapack.dll
> 
> build/temp.cygwin-1.3.3-i686-2.1/flapackmodule.o: In function `initflapack':
> /home/software/scipy/linalg/flapackmodule.c:7855: undefined reference to `_imp__PyFortranObject_NewAsAttr'
> build/temp.cygwin-1.3.3-i686-2.1/fortranobject.o: In function `PyFortranObject_New':
> [snip]
> collect2: ld returned 1 exit status
> error: command 'gcc' failed with exit status 1
> 
> As I said above I tried playing with DL_EXPORTS, to no avail.

Did you compile with -DUSE_DL_IMPORT?  If not, then the above unresolved
link errors are to be expected.

> Thank you for your help, hope you guys have some more ideas...:))

You may have better luck on the Distutils mailing list:

    [email-masked]

The only other suggestion that I have is to start with a simple Cygwin
Python extension so you can really understand what is going on before
trying something significantly more complicated like a f2py generated
extension.  For example, try the Demo/extend in the Python source tree --
all you need to do is execute "make_shared".

Jason

--
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/