[Numpy-discussion] PyArray_API, NO_IMPORT, and NO_IMPORT_ARRAY

Rodgers, Kevin KRodgers at ryanaero.com
Tue Apr 17 15:07:30 CDT 2001


I'm working on a project where I'm embedding Python and NumPy (on Win32).
For various reasons, I need to have all of my source files as C++, even
though I'm not using any C++ features (just using it as a "better C").  When
Visual C++ goes to link, I get the following error:

Linking...
vtuav_sim_wrap.obj : error LNK2005: _PyArray_API already defined in
vtuav_sim.obj
vtuav_sim_wrap.obj : warning LNK4006: _PyArray_API already defined in
vtuav_sim.obj; second definition ignored
   Creating library Release/vtuav_simc.lib and object Release/vtuav_simc.exp
Release/vtuav_simc.dll : fatal error LNK1169: one or more multiply defined
symbols found
Error executing link.exe.

The error is caused by the following lines in arrayobject.h:

/* C API address pointer */ 
#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
extern void **PyArray_API;
#else
void **PyArray_API;
#define NO_PYARRAY_API
#endif

Because I'm including the arrayobject.h header in two different source code
modules, and neither NO_IMPORT or NO_IMPORT_ARRAY are defined, the "else"
clause gets executed, which causes the "multiply defined symbol" error.
This also appears to be the root cause of the problems currently being
discussed on the list about MacOS X.

So, how can this problem be fixed?  I must confess that I don't understand
the code in arrayobject.h that uses PyArray_API. Any ideas?  Thanks in
advance . . .

--
Kevin Rodgers  Northrop Grumman Ryan Aeronautical  krodgers at ryanaero.com
"This one goes up to eleven." -- Nigel Tufnel





More information about the Numpy-discussion mailing list