[Numpy-discussion] extension module with swig

2008-11-04 Thread Giovanni Samaey
Dear all,

I am unsure about the correct place to put this question -- If this  
isn't the correct list, please let me know which place is more  
appropriate.

I am trying to build an extension module in python that calls a C  
routine that depends on the GNU Scientific Library.
I am using swig to wrap the c-file and the numpy.i file that is  
included with numpy for the typemaps.  To build the module, I am using  
distutils, with a modified version of the setup.py file that was  
included with the examples (in order to link against gsl).

Although the build succeeds wtihout problems, I am getting "undefined  
symbol" errors from gsl when importing the module in python.  I am  
attaching the source code of the simplest possible example below  
together with the error messages.  Note that I am trying to link  
against my own gsl in my home directory.  There is no system-wide one  
available.

I get the feeling that I am doing something silly, but I am unable to  
put the finger on it.  Any help would be greatly appreciated.

As a c-file I have : test.c

#include 
#include 
# include 

double var;
void test(double *x, double *y, double *z, int n) {
   int i;
 const gsl_rng_type *T;
 gsl_rng *r;

//gsl_rng_env_setup();

//T = gsl_rng_default;
 T = gsl_rng_mt19937;
 r = gsl_rng_alloc(T);
   for (i=0;i", line 1, in ?
   File "test.py", line 7, in ?
 import _test
ImportError: ./_test.so: undefined symbol: gsl_rng_mt19937

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] extension module with swig

2008-11-04 Thread Giovanni Samaey
And, additionally setting the environment variable LD_LIBRARY_PATH to  
start with /data/home/u0038151/lib instead of ending with it, it picks  
up my own gsl, and gives the error message

0 [EMAIL PROTECTED] dot2 $ python -c "import dot"
Traceback (most recent call last):
  File "", line 1, in ?
  File "dot.py", line 7, in ?
import _dot
ImportError: /data/home/u0038151/lib/libgsl.so.0: undefined symbol:  
cblas_ctrmv

Again something different...

Giovanni

On 04 Nov 2008, at 11:46, Giovanni Samaey wrote:

> Hi Matthieu,
>
> thank you for your prompt reply.
>
> On 04 Nov 2008, at 11:24, Matthieu Brucher wrote:
>
>>> # dot extension module
>>> _test = Extension("_test",
>>>   ["test_wrap.c",
>>>"test.c"],
>>>   include_dirs = [numpy_include,'/data/home/
>>> u0038151/include'],
>>>  library_dirs = ['/data/home/u0038151/lib']
>>> )
>
> This is where is specify the directory where my header files are, as  
> well as the directory of the library.  If I add, from your  
> suggestion libraries = ['gsl'] to that list, it tries to pick up a  
> gsl that is installed in /usr/lib (but there are no headers there.)
> Then I get the message:
>
> python -c "import dot"
> Traceback (most recent call last):
>  File "", line 1, in ?
>  File "dot.py", line 7, in ?
>import _dot
> ImportError: /usr/lib/libgsl.so.0: undefined symbol: cblas_dsdot
>
> So it finds the gsl symbols in the system library (not mine),  
> probably combined with my headers, and then has a different error.
>
> Giovanni

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] extension module with swig

2008-11-04 Thread Matthieu Brucher
> # dot extension module
> _test = Extension("_test",
> ["test_wrap.c",
>  "test.c"],
> include_dirs = [numpy_include,'/data/home/
> u0038151/include'],
>library_dirs = ['/data/home/u0038151/lib']
>   )
>
> # NumyTypemapTests setup
> setup(name= ["test"],
>   description = "test c module swigging",
>   author  = "Giovanni Samaey",
>   py_modules  = ["test"],
>   ext_modules = [_test ]
>   )
>
> The error message is the following:
>
> 0 [EMAIL PROTECTED] dot2 $ python -c "import test"
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "test.py", line 7, in ?
> import _test
> ImportError: ./_test.so: undefined symbol: gsl_rng_mt19937

Hi,

Where did you add the gsl library when building the extension ? I
think the Extension class is missing an argument (library = ["gsl"] or
something like that)

Matthieu
-- 
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] extension module with swig

2008-11-04 Thread Christopher Barker
Giovanni Samaey wrote:
> changing the library path and explicitly adding libraries =['gsl',  
> 'gslcblas'] did the trick !

one other suggestion:

if you want this to run any other machine, you might want to build gsl 
as a static lib, so it will get linked directly into your extension, and 
your extension will no longer rely on having it installed.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

[EMAIL PROTECTED]
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] extension module with swig

2008-11-04 Thread Giovanni Samaey
Thanks,

changing the library path and explicitly adding libraries =['gsl',  
'gslcblas'] did the trick !
Thank you so much !

Giovanni

On 04 Nov 2008, at 12:09, Matthieu Brucher wrote:

> The issue with the LD_LIBRARY_PATH would come up in any case. You have
> to put your gsl library folder before the system one if you want your
> gsl library to be used.
>
> For the cblas issue, it seems from Google you have to link against a
> CBLAS library as well to use the GSL (for instance blas or atlas
> shoule be enough).
>
> Matthieu
>
> 2008/11/4 Giovanni Samaey <[EMAIL PROTECTED]>:
>> And, additionally setting the environment variable LD_LIBRARY_PATH to
>> start with /data/home/u0038151/lib instead of ending with it, it  
>> picks
>> up my own gsl, and gives the error message
>>
>> 0 [EMAIL PROTECTED] dot2 $ python -c "import dot"
>> Traceback (most recent call last):
>> File "", line 1, in ?
>> File "dot.py", line 7, in ?
>>   import _dot
>> ImportError: /data/home/u0038151/lib/libgsl.so.0: undefined symbol:
>> cblas_ctrmv
>>
>> Again something different...
>>
>> Giovanni
>>
>> On 04 Nov 2008, at 11:46, Giovanni Samaey wrote:
>>
>>> Hi Matthieu,
>>>
>>> thank you for your prompt reply.
>>>
>>> On 04 Nov 2008, at 11:24, Matthieu Brucher wrote:
>>>
> # dot extension module
> _test = Extension("_test",
>  ["test_wrap.c",
>   "test.c"],
>  include_dirs = [numpy_include,'/data/home/
> u0038151/include'],
> library_dirs = ['/data/home/u0038151/lib']
>)
>>>
>>> This is where is specify the directory where my header files are, as
>>> well as the directory of the library.  If I add, from your
>>> suggestion libraries = ['gsl'] to that list, it tries to pick up a
>>> gsl that is installed in /usr/lib (but there are no headers there.)
>>> Then I get the message:
>>>
>>> python -c "import dot"
>>> Traceback (most recent call last):
>>> File "", line 1, in ?
>>> File "dot.py", line 7, in ?
>>>   import _dot
>>> ImportError: /usr/lib/libgsl.so.0: undefined symbol: cblas_dsdot
>>>
>>> So it finds the gsl symbols in the system library (not mine),
>>> probably combined with my headers, and then has a different error.
>>>
>>> Giovanni
>>
>> ___
>> Numpy-discussion mailing list
>> Numpy-discussion@scipy.org
>> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
>
> -- 
> Information System Engineer, Ph.D.
> Website: http://matthieu-brucher.developpez.com/
> Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
> LinkedIn: http://www.linkedin.com/in/matthieubrucher
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] extension module with swig

2008-11-04 Thread Giovanni Samaey
Hi Matthieu,

thank you for your prompt reply.

On 04 Nov 2008, at 11:24, Matthieu Brucher wrote:

>> # dot extension module
>> _test = Extension("_test",
>>["test_wrap.c",
>> "test.c"],
>>include_dirs = [numpy_include,'/data/home/
>> u0038151/include'],
>>   library_dirs = ['/data/home/u0038151/lib']
>>  )

This is where is specify the directory where my header files are, as  
well as the directory of the library.  If I add, from your suggestion  
libraries = ['gsl'] to that list, it tries to pick up a gsl that is  
installed in /usr/lib (but there are no headers there.)
Then I get the message:

python -c "import dot"
Traceback (most recent call last):
   File "", line 1, in ?
   File "dot.py", line 7, in ?
 import _dot
ImportError: /usr/lib/libgsl.so.0: undefined symbol: cblas_dsdot

So it finds the gsl symbols in the system library (not mine), probably  
combined with my headers, and then has a different error.

Giovanni

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] extension module with swig

2008-11-04 Thread Matthieu Brucher
The issue with the LD_LIBRARY_PATH would come up in any case. You have
to put your gsl library folder before the system one if you want your
gsl library to be used.

For the cblas issue, it seems from Google you have to link against a
CBLAS library as well to use the GSL (for instance blas or atlas
shoule be enough).

Matthieu

2008/11/4 Giovanni Samaey <[EMAIL PROTECTED]>:
> And, additionally setting the environment variable LD_LIBRARY_PATH to
> start with /data/home/u0038151/lib instead of ending with it, it picks
> up my own gsl, and gives the error message
>
> 0 [EMAIL PROTECTED] dot2 $ python -c "import dot"
> Traceback (most recent call last):
>  File "", line 1, in ?
>  File "dot.py", line 7, in ?
>import _dot
> ImportError: /data/home/u0038151/lib/libgsl.so.0: undefined symbol:
> cblas_ctrmv
>
> Again something different...
>
> Giovanni
>
> On 04 Nov 2008, at 11:46, Giovanni Samaey wrote:
>
>> Hi Matthieu,
>>
>> thank you for your prompt reply.
>>
>> On 04 Nov 2008, at 11:24, Matthieu Brucher wrote:
>>
 # dot extension module
 _test = Extension("_test",
   ["test_wrap.c",
"test.c"],
   include_dirs = [numpy_include,'/data/home/
 u0038151/include'],
  library_dirs = ['/data/home/u0038151/lib']
 )
>>
>> This is where is specify the directory where my header files are, as
>> well as the directory of the library.  If I add, from your
>> suggestion libraries = ['gsl'] to that list, it tries to pick up a
>> gsl that is installed in /usr/lib (but there are no headers there.)
>> Then I get the message:
>>
>> python -c "import dot"
>> Traceback (most recent call last):
>>  File "", line 1, in ?
>>  File "dot.py", line 7, in ?
>>import _dot
>> ImportError: /usr/lib/libgsl.so.0: undefined symbol: cblas_dsdot
>>
>> So it finds the gsl symbols in the system library (not mine),
>> probably combined with my headers, and then has a different error.
>>
>> Giovanni
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion