[Numpy-discussion] PY_ARRAY_UNIQUE_SYMBOL

Bill Spotz wfspotz@sandia....
Wed May 21 18:31:17 CDT 2008

On May 21, 2008, at 5:15 PM, Robert Kern wrote:

> On Wed, May 21, 2008 at 3:34 PM, Bill Spotz <wfspotz@sandia.gov>  
> wrote:
>> I am running into a problem with a numpy-compatible extension module
>> that I develop, and I believe it has to do with  
>> I set PY_ARRAY_UNIQUE_SYMBOL to "PyTrilinos".
> Why? My understanding is also limited, but it does not appear to me to
> be something one should change.

My understanding is that if your extension module requires more than  
one source file, then this macro needs to be set to something  
reasonably unique to your project.  And that NO_IMPORT_ARRAY needs to  
be set in those files that do not call import_array().

>> On my machine (Mac OS
>> X), the module loads and works properly.  Another user, however (on
>> Ubuntu), gets the following:
>>    ImportError: Failure linking new module: /usr/local/lib/python2.4/
>> site-
>>    packages/PyTrilinos/_Epetra.so: Symbol not found: _PyTrilinos
>>    Referenced from: /usr/local/lib/libpytrilinos.dylib
>>    Expected in: dynamic lookup
> ??? How did an Ubuntu user get a hold of a .dylib?

I could have this wrong.  He is asking me questions about Mac OS X and  
Ubuntu simultaneously.  But going back through his emails, I thought I  
had this right.

>> On my machine, I see:
>>    $ nm libpytrilinos.dylib | grep PyTrilinos
>>         U _PyTrilinos
>>         ...
>> and I'm not sure where the symbol actually IS defined.
> It gets generated into __multiarray_api.h:
> #endif
> #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
> extern void **PyArray_API;
> #else
> void **PyArray_API;
> #else
> static void **PyArray_API=NULL;
> #endif
> #endif
> How did this symbol end up in a .dylib rather than a Python extension
> module? I think it might be difficult to arrange for a non-extension
> dynamic library to call into numpy.

It is designed so that the extension modules (plural -- there are many  
of them) link to the dylib that has the symbol.  The code in this  
dylib is only ever accessed through those extension modules.

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: wfspotz@sandia.gov **

More information about the Numpy-discussion mailing list