linking CLAPACK with C++

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

linking CLAPACK with C++

Postby lucky0002 » Tue May 31, 2011 12:50 pm

Hello,
I am working on porting of lapack funtions , I have some c++ code, and I have to do performance analysis so my code also calls the CLAPACK routine.

Say , DGESV I have a code that implements the DGESV and I have to compare the results with the CLAPACK dgesv_

but actually the compiler is not able to link properly with the library.

I have downloaded the clapack and
generated the libraries
lapack_LINUX.a
blas_LINUX.a
libf2c.a

I am linking with above 3 as well as with -lm in the end


The problem that I am facing is like :
I run the CLAPACK routine alone in a ".C" file and use gcc things work fine.

But when I combine the CLAPACK call with the my c++ code in a ".CPP" file and compiling with g++/c++ it says "UNDEFINED REFERENCE TO dgesv_(long *, long *, double *, long *, long *, double *, long *, long *)"


i tried to put my code in a ".C" file and compiling with "GCC" then the problem is that compiler is not able to find headers like 'iostream'

Is there a proper way to make this happen all right.
Please suggest me something.


One thing that is coming to my mind is that I have compiled the CLAPACK with GCC.
I tried to modify the make.inc provided with CLAPACK.tgz but I was getting some errors please tell me if compiling the CLAPACK again with g++/c++ will work? If yes then please tell me a proper way
lucky0002
 
Posts: 7
Joined: Mon Mar 07, 2011 7:25 am

Re: linking CLAPACK with C++

Postby rodney » Wed Jun 01, 2011 1:29 pm

Make sure that your function prototype for dgesv_ in your C++ file looks like this:

extern "C" dgesv_(long *, long *, double *, long *, long *, double *, long *, long *);

Without the extern "C" part the C++ linker will not find dgesv_.

Rodney
rodney
 
Posts: 48
Joined: Thu Feb 10, 2011 8:20 pm
Location: Colorado College

Re: linking CLAPACK with C++

Postby lucky0002 » Fri Jun 03, 2011 6:26 am

Thanks that worked :)
Actually when I first tried it was giving error that extern "C" declaration conflicts with the older definition of the dgesv_
then I removed the #include "clapack.h"

though have f2c.h included with the extern "C" linkage specification in main , I have things working :)
lucky0002
 
Posts: 7
Joined: Mon Mar 07, 2011 7:25 am

Re: linking CLAPACK with C++

Postby lucky0002 » Sun Jun 05, 2011 7:02 am

Hey ,
actually I have to do the performance comparison , so I wish to run the ACML( AMD Core Math library ) with CLAPACK .
But i am getting linking problem because the acml libs and CLAPACK libs contains the same definitions so my program is picking definitions from ACML libs.

FOr both the function calls AML lib is being used , please suggest me how to make the proper linking happen.

Thanks
lucky0002
 
Posts: 7
Joined: Mon Mar 07, 2011 7:25 am

Re: linking CLAPACK with C++

Postby Julien Langou » Sun Jun 05, 2011 8:30 am

Hello,

Best is to write one main and link it once with acml to get an exe and link it a second time with reference lapack to get a second exe.
Then run both exe for the comparison.

Getting one exe that calls two functions which share the same name but live in two different libraries can be tricky. I'll disrecommend. (Although I can see the interest of doing so in your particular case.)

Cheers,
Julien.
Julien Langou
 
Posts: 734
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA


Return to Linking Problem

Who is online

Users browsing this forum: No registered users and 0 guests