[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Fwd: Linking lapack and C standard library



On Thu, 14 Mar 2013, Francesco Pietra wrote:

As to the problem of linking lapack, I wonder whether this is because
it deal of a C-language code, requiring a fine-tuned calling. Is any C
interface to lapack in Debian?

Ciao Francesco.
There are several implementation of lapack in debian. You should make sure
to link against its dependencies as well. On my wheezy computer, if I do
ls -l /usr/lib/liblapack.so I get
/usr/lib/liblapack.so -> /etc/alternatives/liblapack.so
and in turn /etc/alternatives/liblapack.so -> /usr/lib/lapack/liblapack.so
/usr/lib/lapack/liblapack.so belongs to liblapack-dev. So in my case
liblapack.so points to the alternative installed by the liblapack-dev
package (there is another alternative, for example, in
/usr/lib/atlas-base/atlas, installed by libatlas-base-dev). If I do ldd /usr/lib/liblapack.so, I get:
ldd /usr/lib/liblapack.so
	linux-vdso.so.1 =>  (0x00007fff153fe000)
	libblas.so.3 => /usr/lib/libblas.so.3 (0x00007ffe79e46000)
	libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3
	(0x00007ffe79b2f000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffe798ad000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
	(0x00007ffe79697000)
	libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0
	(0x00007ffe79461000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffe790d7000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
	(0x00007ffe78ebb000)
	/lib64/ld-linux-x86-64.so.2 (0x00007ffe7c02a000)

So I know from the above that if I want to link a code with liblapack, I
also need to link against libblas, libpthread and libm at least. If the
compiler does not include them automatically (i.e. if I am not using
gfortran to compile) I also need to explicitly include libgfortran, and if I
am not using gcc compilers at all, I need to even add libgcc_s and
libquadmath (but using these libraries compiled with gnu compilers with
another compiler would be looking for trouble).

As to explicitely linking against libstdc++, here you may have another
problem: I don't have a libstdc++.so or a libstdc++.a in my library path, it
is in /usr/lib/gcc/x86_64-linux-gnu/4.x and is usually never explicitely
linked, it is always automatically included by the compiler. In any case you
will not find it in /usr/lib, nor in /usr/lib/x86_64-linux-gnu (the default
directory for 64bit libs in a multiarch system, as debian is since wheezy).

So in my case I would need to do
LIBS="-llapack -lblas -lpthread -lm -L/usr/lib/gcc/x86_64-linux-gnu/4.7 \
-lstdc++"

As to headers, liblapack is fortran native, it can be called from C/C++ but
still it is a fortran library. If you want the native C/C++ library, you
should use liblapacke, which comes with the liblapacke and liblapacke-dev
packages in debian. But while I sometimes used it in my codes, I have yet to
see a released package using it. The liblapacke-dev package does include
header files.

Ciao
Giacomo

--
_________________________________________________________________

Giacomo Mulas <gmulas@oa-cagliari.inaf.it>
_________________________________________________________________

OSSERVATORIO ASTRONOMICO DI CAGLIARI
Str. 54, Loc. Poggio dei Pini * 09012 Capoterra (CA)

Tel. (OAC): +39 070 71180 248     Fax : +39 070 71180 222
Tel. (UNICA): +39 070 675 4916
_________________________________________________________________

"When the storms are raging around you, stay right where you are"
                         (Freddy Mercury)
_________________________________________________________________


Reply to: