[Haskell-cafe] Re: Linking hmatrix without LAPACK

Duane Johnson duane.johnson at gmail.com
Mon Apr 6 15:51:45 EDT 2009


Hi Alberto!

Thanks for your informative reply.  I looked in to the versions of  
liblapack on my system... it turns out there is indeed a  
liblapack.dylib that (apparently) comes with Mac OS X.  How to tell  
ghc to link to that instead is still in question.

I can run simple matrix operations in ghci as you suggest (in fact,  
"runTests 20" succeeds wonderfully); however, I created the following  
simple module (test.hs) and it fails:

> module Main where
>   import Numeric.LinearAlgebra.Tests
>
>   main = do
>     runTests 20

I tried plain "--make", as well as the "-dynamic" flag, and then I  
tried the "-L" shell argument to point to the /usr/lib dir where the  
liblapack.dylib library is located:


> $ ghc --make test.hs -o test
> [1 of 1] Compiling Main             ( test.hs, test.o )
> Linking test ...
> ld: in /opt/local/lib/liblapack.a(
> ), not a valid archive member
> collect2: ld returned 1 exit status
>
> $ ghc --make -dynamic test.hs -o test
> Linking test ...
> ld: library not found for -lHShmatrix-0.5.0.1-ghc6.10.1
> collect2: ld returned 1 exit status
>
> $ ghc --make -L/usr/lib test.hs -o test
> Linking test ...
> Undefined symbols:
>   "_zgemm_", referenced from:
>       _multiplyC in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_zgesv_", referenced from:
>       _linearSolveC_l in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_zpotrf_", referenced from:
>       _chol_l_H in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_dpotrf_", referenced from:
>       _chol_l_S in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_dgemm_", referenced from:
>       _multiplyR in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_dgesv_", referenced from:
>       _linearSolveR_l in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_zgetrf_", referenced from:
>       _lu_l_C in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_zgetrs_", referenced from:
>       _luS_l_C in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_dgetrf_", referenced from:
>       _lu_l_R in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>   "_dgetrs_", referenced from:
>       _luS_l_R in libHShmatrix-0.5.0.1.a(lapack-aux.o)
> ld: symbol(s) not found
> collect2: ld returned 1 exit status


I attempted to install hmatrix with the "-faccelerate" option, but  
when using "ghc --make" for the above test code, I received the same  
error messages noted previously.  Is there a way to tell if the "- 
faccelerate" was acknowledged and that the alternate library was used?

One more clue: I took a look at the directions found on the page at  
mit.edu/harold... it turns out I had installed atlas/lapack  
unnecessarily.  That explains the mysterious "not a valid archive  
member" message.  Nevertheless, I am still befuddled by the "Undefined  
symbols" above.  ghc --make is still unable to figure out where the  
liblapack.dylib file is in spite of ghci's success.

Any suggestions from here?

Regards,
Duane Johnson

P.S. I'm CC'ing the Haskell Cafe so that our journey so far can be  
archived.



On Apr 6, 2009, at 12:22 PM, Alberto Ruiz wrote:

> Hi Duane,
>
> I have seen your messages to Haskell Cafe but I am still thinking  
> about the problem... :)
>
> Can you run simple matrix operations in ghci?
>
> $ ghci
> Prelude> import Numeric.LinearAlgebra
> Prelude Numeric.LinearAlgebra> let m = (2><2) [1..4 :: Double]
>
> (...Loading packages...)
>
> Prelude Numeric.LinearAlgebra> m <> m
> (2><2)
> [  7.0, 10.0
> , 15.0, 22.0 ]
>
> If so, some version of blas/lapack can be found in your system, it  
> is strange that ghc --make doesn't find them.
>
> Perhaps the problem is that dynamic libraries like liblapack.so are  
> required instead of static ones like liblapack.a. (In ubuntu they  
> are in the "devel" packages for blas/lapack.)
>
> I am not familiar with Mac OS, but if you can use the "accelerate  
> framework" in your system you may try the -faccelerate configuration  
> option for hmatrix:
>
> cabal install hmatrix -faccelerate
>
> See also the following page (steps 3-8). It explains how to install  
> hmatrix on Mac OS (required for other project).
>
> http://mit.edu/harold/Public/easyVisionNotes.html
>
> Please let me know if any of these methods works for you.
>
> Thanks for your message,
>
> Alberto
>
>
>
> Duane Johnson wrote:
>> Hi Alberto,
>> I've been very happy with hmatrix as I've used it in ghci, and I  
>> should first thank you for making such an excellent package.  I've  
>> had trouble when linking it using "ghc --make" on Mac OS  
>> (Leopard).  Below are two messages I sent to the Haskell Cafe  
>> mailing list.  Do you have any insight into either question:
>> 1. How to link without atlas/lapack
>> 2. What the "not a valid archive member" message means?
>> Thank you!
>> Duane Johnson
>> Brigham Young University
>> Provo, UT
>> Begin forwarded message:
>>> From: Don Stewart <dons at galois.com>
>>> Date: April 5, 2009 11:48:38 PM MDT
>>> To: Duane Johnson <duane.johnson at gmail.com>
>>> Subject: Re: [Haskell-cafe] Re: Linking hmatrix without LAPACK
>>>
>>> It would be best to contact the author of hmatrix directly.
>>>
>>>
>>> duane.johnson:
>>>> On a related note, I've installed Atlas, and I get the following  
>>>> error
>>>> when linking:
>>>>
>>>>> Linking SilkwormGame ...
>>>>> ld: in /opt/local/lib/liblapack.a(), not a valid archive member
>>>>> collect2: ld returned 1 exit status
>>>>
>>>> How would I go about diagnosing this?  I've never seen an ld  
>>>> error like
>>>> that.
>>>>
>>>> Thanks again!
>>>> Duane Johnson
>>>>
>>>>
>>>> On Apr 5, 2009, at 11:02 PM, Duane Johnson wrote:
>>>>
>>>>> I'm curious if there is a quick fix to this.  I installed GLS and
>>>>> hmatrix, and it runs wonderfully together in ghci.  When I run  
>>>>> ghc --
>>>>> make, however, I run into the following link dependency:
>>>>>
>>>>> Linking SilkwormGame ...
>>>>> Undefined symbols:
>>>>> "_dgemm_", referenced from:
>>>>>    _multiplyR in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>>>>> "_dgesv_", referenced from:
>>>>>    _linearSolveR_l in libHShmatrix-0.5.0.1.a(lapack-aux.o)
>>>>>    ... etc
>>>>>
>>>>> Is there a way to tell ghc to not link these?  Or am I making a  
>>>>> poor
>>>>> assumption that if my code runs in ghci, it does not need LAPACK?
>>>>>
>>>>> Thanks,
>>>>> Duane Johnson
>>>>
>>>> _______________________________________________
>>>> Haskell-Cafe mailing list
>>>> Haskell-Cafe at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list