Linking problem with atlas-lapack libs

Post here if you have a question about linking your program with LAPACK or ScaLAPACK library

Linking problem with atlas-lapack libs

Postby someguynameddave » Fri Dec 17, 2010 2:24 pm

Linking problem with atlas-lapack libs
Hey gang,

I am trying to write some linear algebra software on Ubuntu Karmic, and am getting some pure evil at link time. Here is a simple test problem I wrote up:

#include <clapack.h>
#include <iostream>

using namespace std;

int main()
{
double matrix[] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
const int info = clapack_dpotrf( CblasRowMajor, CblasUpper, 3, matrix, 3 );

cout << "info: " << info << ", matrix: " << endl;
cout << "(" << matrix[0] << ",\t" << matrix[3] << ",\t" << matrix[6] << "," << endl;
cout << " " << matrix[1] << ",\t" << matrix[4] << ",\t" << matrix[7] << "," << endl;
cout << " " << matrix[2] << ",\t" << matrix[5] << ",\t" << matrix[8] << ")" << endl;

return 0;
}

If I try compiling that with the following command:

$ g++ -llapack -lblas lapacktest.cc

I get

lapacktest.cc:(.text+0xd9): undefined reference to `clapack_dpotrf(CBLAS_ORDER, CBLAS_UPLO, int, double*, int)'

So, that function doesn't appear to be in the library. Sure enough, if I do

$ objdump -T /usr/lib/liblapack.so | grep clapack_dpotrf

I get nothing. However, if I do

$ ls -la /usr/lib/liblapack*.so

I get:

lrwxrwxrwx 1 root root 32 2010-12-16 17:22 /usr/lib/liblapack-3.so -> /etc/alternatives/liblapack-3.so
lrwxrwxrwx 1 root root 22 2010-12-16 17:22 /usr/lib/liblapack_atlas.so -> liblapack_atlas.so.3gf
lrwxrwxrwx 1 root root 34 2010-12-16 17:22 /usr/lib/liblapackgf-3.so -> /etc/alternatives/liblapackgf-3.so
lrwxrwxrwx 1 root root 16 2010-12-16 17:22 /usr/lib/liblapack.so -> liblapack.so.3gf

Sure enough, doing

$ objdump -T /usr/lib/liblapack_atlas.so | grep clapack_dpotr

gives

0000000000014ff4 g DF .text 0000000000000134 Base clapack_dpotrf

So, that has the symbol I need, right? Wrong. If I compile with that lib like so:

$ g++ -llapack_atlas -lblas lapacktest.cc

I still get

lapacktest.cc:(.text+0xd9): undefined reference to `clapack_dpotrf(CBLAS_ORDER, CBLAS_UPLO, int, double*, int)'

Similar for all the other libs (except liblapack, which complains about a tonne of other stuff as well). Running dpkg tells me that I have the following packages installed:

$ dpkg -l | grep lapack
ii liblapack-dev 3.2.1-1 library of linear algebra routines 3 - stati
ii liblapack3gf 3.2.1-1 library of linear algebra routines 3 - share

So, what is going on there? Is this a problem with the package? (Do the libs just not match the headers?) Any help would be greatly appreciated.

Dave
someguynameddave
 
Posts: 2
Joined: Fri Dec 17, 2010 2:08 pm

Re: Linking problem with atlas-lapack libs

Postby admin » Fri Dec 17, 2010 3:04 pm

Dave,
I would advice to get a fresh install of LAPACK.
For your info, the LAPACK included in ATLAS is only a subset.

Also you are looking to use CLAPACK, which was a translated code form Fortran to C.
We just release a new Standard C Interface to LAPACK in collaboration with INTEL.

So I would advice to download the LAPACK 3.3.0 package (Fortran library)
and get the Standard C language APIs for LAPACK (lapacke)
You can find everything on netlib: http://www.netlib.org/lapack/

Julie
admin
Site Admin
 
Posts: 504
Joined: Wed Dec 08, 2004 7:07 pm

Re: Linking problem with atlas-lapack libs

Postby someguynameddave » Fri Jan 14, 2011 3:20 pm

Actually, turns out that I just needed the old

extern "C"{...}

around my #include <clapack.h>

gcc was looking for mangled C++ symbol names, but the library only has old-skool C symbols.
someguynameddave
 
Posts: 2
Joined: Fri Dec 17, 2010 2:08 pm


Return to Linking Problem

Who is online

Users browsing this forum: No registered users and 1 guest

cron