[Numpy-discussion] Problems compiling ufuncs example (2)

Kosta Gaitanis kosh at skynet.be
Tue Oct 11 05:08:38 CDT 2005


Kosta Gaitanis wrote:
Hi again,
I downloaded mingw32 and this seemed to fix the compilator problem. 
However I still can't build the ufunc example !

This time I tried :

       python setup.py build_ext --compiler=mingw32

and get the following output:

    running build_ext
    building 'numarray.foo._foo' extension
    c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Iinclude
    -Iinclude/numarray -Ic
    :\python24\Include
    umarray -IC:\Python24\include -IC:\Python24\PC -c foo/Src/_foo.c -o
    build\temp.w
    in32-2.4\Release\foo\src\_foo.o
    foo/Src/_foo.c:8: warning: ignoring #pragma warning
    foo/Src/_foo.c: In function `init_funcDict':
    foo/Src/_foo.c:26: warning: unused variable `keytuple'
    foo/Src/_foo.c:26: warning: unused variable `cfunc'
    writing build\temp.win32-2.4\Release\foo\src\_foo.def
    c:\mingw\bin\gcc.exe -mno-cygwin -shared -s
    build\temp.win32-2.4\Release\foo\src
    \_foo.o build\temp.win32-2.4\Release\foo\src\_foo.def -LLib
    -LC:\Python24\libs -
    LC:\Python24\PCBuild -lpython24 -lmsvcr71 -o
    build\lib.win32-2.4\numarray\foo\_f
    oo.pyd
    build\temp.win32-2.4\Release\foo\src\_foo.o(.text+0x87):_foo.c:
    undefined refere
    nce to `_imp__PyCObject_Type'
    build\temp.win32-2.4\Release\foo\src\_foo.o(.text+0xa6):_foo.c:
    undefined refere
    nce to `_imp__PyExc_ImportError'
    collect2: ld returned 1 exit status
    error: command 'gcc' failed with exit status 1

If I remove the comments from the line     libraries = ['ttf']    (at 
the end of setup.py) and try again I get this error :

    running build_ext
    building 'numarray.foo._foo' extension
    c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Iinclude
    -Iinclude/numarray -Ic
    :\python24\Include
    umarray -IC:\Python24\include -IC:\Python24\PC -c foo/Src/_foo.c -o
    build\temp.w
    in32-2.4\Release\foo\src\_foo.o
    foo/Src/_foo.c:8: warning: ignoring #pragma warning
    foo/Src/_foo.c: In function `init_funcDict':
    foo/Src/_foo.c:26: warning: unused variable `keytuple'
    foo/Src/_foo.c:26: warning: unused variable `cfunc'
    writing build\temp.win32-2.4\Release\foo\src\_foo.def
    c:\mingw\bin\gcc.exe -mno-cygwin -shared -s
    build\temp.win32-2.4\Release\foo\src
    \_foo.o build\temp.win32-2.4\Release\foo\src\_foo.def -LLib
    -LC:\Python24\libs -
    LC:\Python24\PCBuild -lttf -lpython24 -lmsvcr71 -o
    build\lib.win32-2.4\numarray\
    foo\_foo.pyd
    c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe:
    cannot fin
    d -lttf
    collect2: ld returned 1 exit status
    error: command 'gcc' failed with exit status 1

Can someone tell me what I'm doing wrong please.

Thanks
Kosta

> Hi all,
>
> I'm trying to run the UFunc example in the Numarray manual 
> (http://stsdas.stsci.edu/numarray/numarray-1.1.html/node32.html)
> but when I run the command
>
>    python setup.py buil_ext
>
>
> I get the following output :
>
>    running build_ext
>    error: Python was built with version 7.1 of Visual Studio, and
>    extensions need t
>    o be built with the same version of the compiler, but it isn't 
> installed
>
>
> so I installed Visual C++ Toolkit 2003 and then run the same command 
> again and got the following output :
>
>    running build_ext
>    error: the .NET Framework SDK needs to be installed before building
>    extensions f
>    or Python
>
>
> so I installed .NET Framework SDK 1.1 and then tried again.
> I got back the first error...
>
> does anyone have an idea ? What am I doing wrong ?
>
> thanks in advance
> Kosta
>
> I'm using Python24 and NumArray 1.3.3
>
>
> -- setup.py --
> """ This setup demonstrates how to use the numarray code generation
> facilities to define additional ufuncs at the user level.  Universal
> functions apply operators or C-functions elementwise to all of the
> elements of an array or pair of arrays. This setup generates code
> defining three universal functions which are installed as the
> numarray.foo package: Cos, bessel, and bar.
>
> The ufuncs are used like this:
>
> >>> import numarray as na
> >>> import numarray.foo as foo
> >>> a = na.array([1,2,3,4], type='Int32')
> >>> foo.Cos(a)
> array([ 0.54030228, -0.41614684, -0.9899925 , -0.65364361 ], 
> type=Float32)
>
> Note that since a is an Int32 array, Cos(a) first does blockwise
> conversion of a to Float32 before calling the cosine library function.
> """
>
> import distutils, os
> from distutils.core import setup
> from numarray.numarrayext import NumarrayExtension
> from numarray.codegenerator import UfuncModule, make_stub
>
> # ======================================================================
> #
> # Generate the C-code for the numarray.foo._foo extension:
> #
>
> m = UfuncModule("_foo")          
>
> # Inline the code for a couple C functions to be turned into ufuncs.
> # This method lets you define your function here in the setup.py.  An
> # alternate approach would be to link with a libarary or additional C
> # module.
> m.add_code("""
>
> static double c_bessel(double x, double y)
> {
>      double x2=x*x, y2=y*y, diff=x2-y2;
>      return diff*diff/(x2+y2);
> }
>
> static UInt8  c_bar(UInt32 x )
> {
>      return (x >> 24) & 0xFF;
> }
>
> """)
>
> # Method add_ufunc() defines the name of a ufunc, it's corresponding C
> # function which is applied element-wise to all elements of an array,
> # The arity of the ufunc (unary or binary only), and the I/O type
> # signatures which are directly supported by the ufunc.  Binary Ufunc
> # "bessel" is implemented by the inline function "c_bessel" from the
> # add_code() call above.
>
> m.add_ufunc("bessel", "c_bessel", 2, [('Float32', 'Float32'),
>                                      ('Float64', 'Float64')])
>
> # Unary Ufunc "bar" only supports one builtin type signature:
> # UInt32-->UInt8.  Other types are blockwise converted by the ufunc
> # machinery to UInt32 before "c_bar" is called.
>
> m.add_ufunc("bar", "c_bar", 1, [('UInt32','UInt8')])
>
> # Unary Ufunc "cos" is implemented by the C standard library function
> # "cos".  Given a Float32 array, it returns a Float32 array.  Given a
> # Float64 array, it returns a Float64 array.  For other arrays,
> # transparent conversion to one of the supported input types is performed
> # by the ufunc machinery.
>
> m.add_ufunc("cos", "cos", 1, [('Float32', 'Float32'),
>                              ('Float64', 'Float64')])
>
> # The generate() method writes out the complete extension module to the
> # specified C file.
> m.generate("foo/Src/_foo.c")
>
> # ======================================================================
> # Create foo's __init__.py for defining UFuncs corresponding to CFuncs
> # in _foo.  make_stub() emits boiler-plate which makes your extension
> # a package.  The __init__ file imports all the public symbols from
> # C extension _foo making them visible as numarray.foo.
>
> make_stub("foo/Lib/__init__", "_foo")
> # ======================================================================
> #
> # Standard distutils setup for the generated code.
> #
> setup(name = "foo",
>      version = "0.1",
>      maintainer = "Todd Miller",
>      maintainer_email = "jmiller at stsci.edu",
>      description = "foo universal functions for numarray",
>      url = "http://www.stsci.edu/projects/foo/",
>      packages = ["numarray.foo"],
>      package_dir = { "numarray.foo":"foo/Lib" },
>      ext_modules = [ NumarrayExtension( 'numarray.foo._foo', 
> ['foo/Src/_foo.c'],
>                                         # libraries = ['ttf'],
>                                         # include_dirs = ['include'],
>                                         # library_dirs = ['lib']
>                                         )
>                      ]
>      )
>
>





More information about the Numpy-discussion mailing list