Instructions to link LAPACK with C++ (newbie question).

Open discussion regarding features, bugs, issues, vendors, etc.

Instructions to link LAPACK with C++ (newbie question).

Postby paladin12 » Tue Jan 25, 2005 5:21 am

Hi all,

I am trying to link a C++ program to LAPACK but I have not been successful. I understand how to call FORTRAN functions from C++ but cannot link successfully. My development environment is Dev-C++ (http://www.bloodshed.net/devcpp.html).

1. Where can I find a reliable, up-to-date (precompiled) Windows LAPACK library?
2. How do I link to such a LAPACK library on a Windows platform (using Dev-C++)?

Kind Regards,

J
paladin12
 
Posts: 2
Joined: Tue Jan 25, 2005 5:18 am

Linking LAPACK to C++ with Dev-C++

Postby dbindel » Tue Jan 25, 2005 8:13 pm

I'm not too familiar with Dev-C++, but I know it is built on top of the MinGW port of the GNU compiler, with which LAPACK should work fine. If you have a shell environment (e.g. MSYS), you should be able to build LAPACK using the standard makefiles. You may need to edit the time routine (sorry, I will have to go back to check this).

Perhaps you can give a few more details about the error message you received? You're using a particularly tricky combination of compilers, and there are several possible common errors that you might be experiencing:


1. Missing underscore

The GNU Fortran naming convention appends an underscore for binding to C. For example, dgetrf in Fortran becomes dgetrf_ in C. This is *not* the same as what some of the other Windows Fortran compilers do (I think you'd have to use the name DGETRF if you compiled with Compaq Fortran, for example).

2. Missing extern "C"

When you declare Fortran functions for use in the C++ code, you need to wrap them in an extern "C" directive to tell the C++ compiler that it should not use name mangling. For instance, to declare the factorization routine dgetrf, you would write

extern "C" {
int dgetrf_(int *m, int *n, double* a, int* lda, int *ipiv, int *info);
}

or for a more natural C++ interface

extern "C" {
int dgetrf_(const int& m, const int& n, double* a, const int& lda, int *ipiv, int& info);
}

3. Missing BLAS or Fortran support libraries

You will need not only to include LAPACK in your link line, but also a BLAS library and the Fortran support library. Furthermore, if you use -l to indicate your libraries, you need to include the libraries in exactly that order (LAPACK, then BLAS, then the support library). For example, to compile a file foo.cc, I would write

g++ -o foo.x foo.cc -llapack -lblas -lg2c

If you want a fast BLAS, I recommend the Goto BLAS (you can find it with a web search).


From your description, it's hard to tell whether the problem you're having is really with linking the LAPACK library or with one of these peripheral issues.

Hope this helps,
David
dbindel
 
Posts: 1
Joined: Tue Jan 25, 2005 7:49 pm
Location: UC Berkeley

Postby paladin12 » Wed Jan 26, 2005 5:11 am

Hi,

Thanks, but I was really just wondering if it would be possible to use LAPACK/BLAS (in Dev-C++) without the need for MinGW/Cygwin (apart from the subset supplied by Dev-C++). It seems not.

Thanks anyway. J.
paladin12
 
Posts: 2
Joined: Tue Jan 25, 2005 5:18 am


Return to User Discussion

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 1 guest