Hi
I have been trying to install a linear algebra package called LAPACK on my redhat system. The original library was written in FORTRAN but I have got a C version called CLAPACK from netlib.org that was produced using a package called f2c.
I installed both CLAPACK and f2c using rpms and wrote atest program in C which compiled fine. The problem is that I don't want to use C - I want to use C++ and when I tried to compile a C++ program I got the error messege
usr/lib/libf2c.so: undefined reference to 'MAIN__
nothing I do seems to correct the problem. Is there anyone out there with experience of these libraries who can help me? Would be much appreciated. Thanks
Mike
Sastraxi
08-16-2002, 03:16 PM
Even though I don't know what you're talking about, I'd suggest finding a C++ version (that looks like it MAY be just C).
A quick google turned this up:
http://math.nist.gov/lapack++/
Thanks for the advice but I know about Lapack++ and have had a play with it. At first it looked like the answer but it doesn't have anywhere near the functionality of CLAPACK and as luck would have it - the few functions I need are not supported by Lapack++. As far as I can tell I really need to get CLAPACK working.
Mike
Sastraxi
08-16-2002, 03:27 PM
How are you declaring it? Show me the syntax :)
The following C code can be found in the CLAPACK FAQ
* Start of Listing */
#include "f2c.h"
#include "stdio.h"
#include "clapack.h"
#define SIZE 4
void MAIN_(){}
void MAIN__(){}
void _MAIN_(){}
main( )
{
char JOBU;
char JOBVT;
int i;
integer M = SIZE;
integer N = SIZE;
integer LDA = M;
integer LDU = M;
integer LDVT = N;
integer LWORK;
integer INFO;
integer mn = min( M, N );
integer MN = max( M, N );
double a[SIZE*SIZE] = { 16.0, 5.0, 9.0 , 4.0, 2.0, 11.0, 7.0 , 14.0, 3.0, 10.0, 6.0, 15.0, 13.0, 8.0, 12.0, 1.0};
double s[SIZE];
double wk[201];
double uu[SIZE*SIZE];
double vt[SIZE*SIZE];
JOBU = 'A';
JOBVT = 'A';
LWORK = 201;
/* Subroutine int dgesvd_(char *jobu, char *jobvt, integer *m, integer *n,
doublereal *a, integer *lda, doublereal *s, doublereal *u, integer *
ldu, doublereal *vt, integer *ldvt, doublereal *work, integer *lwork,
integer *info)
*/
dgesvd_( &JOBU, &JOBVT, &M, &N, a, &LDA, s, uu,
&LDU, vt, &LDVT, wk, &LWORK, &INFO);
printf("\n INFO=%d", INFO );
for ( i= 0; i< SIZE; i++ ) {
printf("\n s[ %d ] = %f", i, s[ i ] );
}
return 0;
}
/* End of Listing */
Now - This works fine if I compile it using gcc:
gcc test.c -lclapack -lf2c -o test
But I need to use these functions in C++ code so rather than wade right in I try a little modification to the test program - by including <iostream> and changing the printf command to a cout one. So now I have got crude c++ code without changing anything important.
I have modified the CLAPACK header file to include an extern "C" {} statement which is needed for all C functions that are called from c++ (so I have been told).
renaming test.c to test.cpp and doing
g++ test.cpp -lclapack -lf2c -o test
gives me the error talked about earlier. It seems that it is in moving from C to C++ that is causing the problem but I am not sure.
Mike
Sastraxi
08-16-2002, 04:13 PM
Doesn't gcc compile C++ too?
Energon
08-16-2002, 08:21 PM
Just looking at the error, it's having a problem in the f2c so, which means something expecting C linkage is getting C++ linkage (which is what extern "C" does)... and looking at your code, I see this:
void MAIN_(){}
void MAIN__(){}
void _MAIN_(){}
I also see that the error is complaining about MAIN__ (which is defined there)... so my best stab is to say, put extern "C" {} around those three functions... see if that helps. I'm about 90% sure you'll get other linker errors, but I think if you try that, it'll get you passed the error you're getting right now.