[SciPy-User] Linking to BLAS from an extension

Hjalmar Turesson hturesson@gmail....
Wed Oct 26 20:27:52 CDT 2011


I got some expert help and the problem is solved. I needed to add -L
/usr/include -lblas to the make file. The cblas.h resides in /usr/include.
The make file:

# ---- Link ---------------------------
_C_fast_spikesort.so:  C_fast_spikesort.o
gcc -shared C_fast_spikesort.o -o _C_fast_spikesort.so -L /usr/lib -lblas

# ---- gcc C compile ------------------
C_fast_spikesort.o:  C_fast_spikesort.c C_fast_spikesort.h
gcc -c -fPIC C_fast_spikesort.c -I/usr/include/python2.7
-I/usr/lib/python2.7/site-packages/numpy/core/include/numpy


Best,
Hjalmar


On Tue, Oct 25, 2011 at 10:19 PM, Hjalmar Turesson <hturesson@gmail.com>wrote:

> I changed my code to use cblas instead. I include cblas.h and call
> cblas_dgemm. It compiles ok, but I get the same import error:
>
> ImportError: ./_C_fast_spikesort.so: undefined symbol: cblas_dgemm
>
>
> What am I doing wrong?
>
> Thanks,
> Hjalmar
>
>
> On Tue, Oct 25, 2011 at 9:51 PM, Hjalmar Turesson <hturesson@gmail.com>wrote:
>
>> Hi,
>>
>> I'm trying to call dgemm (a BLAS routine) from a C extension. It compiles
>> fine, but when I try to import my python file containing the extension, I
>> get an import error:
>>
>>
>> ImportError: ./_C_fast_spikesort.so: undefined symbol: dgemm_
>>
>>
>> From http://www.math.utah.edu/software/lapack.html I got the impression
>> that gcc doesn't automatically record the location of the BLAS libary, so
>> that at runtime dgemm is not found. Thus, they recommend to put the LDFLAGS
>> line in the make file. But this doesn't help. Make file below:
>>
>> # ---- Record the location of BLAS-----
>> LDFLAGS  = Wl, -rpath /usr/lib
>>
>> # ---- Link ---------------------------
>> _C_fast_spikesort.so:  C_fast_spikesort.o
>>  gcc -shared C_fast_spikesort.o -o _C_fast_spikesort.so
>>
>> # ---- gcc C compile ------------------
>> C_fast_spikesort.o:  C_fast_spikesort.c C_fast_spikesort.h
>>  gcc -c -fPIC C_fast_spikesort.c -I/usr/include/python2.7
>> -I/usr/lib/python2.7/site-packages/numpy/core/include/numpy -L /usr/lib
>> -lblas
>>
>> How should I fix it? Is it better to use cblas, and include cblas.h
>> instead?
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20111026/6b1f3bdb/attachment.html 


More information about the SciPy-User mailing list