MantisBT - CMake
View Issue Details
0012912CMakeModulespublic2012-01-24 21:232013-07-30 09:09
tgallagher 
tgallagher 
normalminoralways
closedno change required 
LinuxUbuntu11.10
CMake 2.8.7 
 
0012912: FindLAPACK does not work when trying static linking
The FindLAPACK module does not work when trying to use static linking. When trying to compile the test file to check if the library works, it gives:

/usr/bin/gfortran CMakeFiles/cmTryCompileExec.dir/testFortranCompiler.f.o -o cmTryCompileExec
 -rdynamic -Wl,--start-group /usr/lib/liblapack.a /usr/lib/libblas.a -Wl,--end-group
/usr/lib/libblas.a(xerbla.o): In function `xerbla_':
(.text+0x0): multiple definition of `xerbla_'
/usr/lib/liblapack.a(xerbla.o):(.text+0x0): first defined here
collect2: ld returned 1 exit status
make[2]: *** [cmTryCompileExec] Error 1
make[2]: Leaving directory `/data/lagrangianBuild/CMakeFiles/CMakeTmp'
make[1]: *** [CMakeFiles/cmTryCompileExec.dir/all] Error 2
make[1]: Leaving directory `/data/lagrangianBuild/CMakeFiles/CMakeTmp'
make: *** [all] Error 2

The double-definition is because the static liblapack already has all the code it needs from libblas in it, but the FindLAPACK module calls FindBLAS and links against both liblapack and libblas.

The solution is to check if BLA_STATIC is set, do not call find_package(BLAS) because the lapack library will already have all the functions it needs in it.
Compile something using the find_package(LAPACK REQUIRED) signature with BLA_STATIC defined.
I have many other fixes related to FindBLAS and FindLAPACK as well as a new module request. If approved for the new module and given access, I can fix this bug as well.
No tags attached.
related to 0014320closed Kitware Robot FindLAPACK doesn't work if BLA_STATIC is set to ON 
Issue History
2012-01-24 21:23tgallagherNew Issue
2012-01-25 17:22Brad KingAssigned To => tgallagher
2012-01-25 17:22Brad KingStatusnew => assigned
2012-01-26 20:38tgallagherNote Added: 0028414
2012-01-26 20:38tgallagherOSOpenSuSE => Ubuntu
2012-01-26 20:38tgallagherOS Version12.1 => 11.10
2012-01-26 20:40tgallagherNote Added: 0028415
2012-01-26 20:40tgallagherStatusassigned => closed
2012-01-26 20:40tgallagherResolutionopen => no change required
2013-07-30 09:09Brad KingRelationship addedrelated to 0014320

Notes
(0028414)
tgallagher   
2012-01-26 20:38   
The problem is actually with the build of LAPACK provided by Ubuntu. Without linking to libblas doesn't work as there are many missing references. Linking with libblas also does not work as the liblapack from Ubuntu contains a duplicate function.

It's possible to overcome this by using the:

-Wl,--allow-multiple-definition

when linking. But, this may have unintended consequences. There is nothing to do from CMake's side to fix this.
(0028415)
tgallagher   
2012-01-26 20:40   
The problem is with Ubuntu's distribution of LAPACK and not CMake.