The LAPACK forum has moved to https://github.com/Reference-LAPACK/lapack/discussions.

undefined reference to CLAPACK functions

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

undefined reference to CLAPACK functions

Postby the-shifter » Mon Apr 14, 2008 2:43 am

I have been stuck for a long time now and am getting really frustrated...someone help me please.

I am using openSuse 10.3 and using gcc ofcourse.
I have built a small test file to try and call one of the CLAPACK function "spotrf".
I have already built all the libraries(BLAS, F2C, LAPACK) as describes in the install file over netlib.
I am using the included standard BLAS library.
I have included all the .h files in my test program and all the includes and the libs in the make file as well.

Problem is it compiles successfully yet at the linking phase it logs error:

spotrftest.o: In function `main':
/home/mfahmy/Documents/SatoLabProj/SPOTRF_C2D/spotrftest.c:74: undefined reference to `spotrf_'
collect2: ld returned 1 exit status
# --error 0x100 --
make: *** [build] Error 255

here is only the important part of my sample test file:

#include "inputs.h"

#include "f2c.h"
#include "blaswrap.h"
#include "clapack.h"
//#include "cblas.h"
#include <stdio.h>
//#include <stdlib.h>
#include <time.h>

extern int spotrf_(char *uplo, integer *n, real *a, integer *lda, integer *info);

int main(void)
{

/* SPOTRF */
spotrf_(&uplo, &n, a, &lda, &info);

}

here is my make file:

all: build


CUDA_LIB_PATH = /usr/local/cuda/lib
CUDA_INC_PATH = /usr/local/cuda/include
CUDA_BIN_PATH = /usr/local/cuda/bin

OTHER_INCS_PATH1 = ./CLAPACK/INCLUDE
OTHER_INCS_PATH2 = ./CLAPACK/BLAS/WRAP
OTHER_INCS_PATH3 = ./CLAPACK/F2CLIBS
OTHER_INCS_PATH4 = ./CLAPACK/F2CLIB/libf2c
OTHER_INCS_PATH5 = ./CLAPACK/F2CLIB/BLAS
OTHER_INCS_PATH6 = ./CLAPACK/BLAS/SRC
OTHER_INCS_PATH7 = ./CLAPACK/SRC


CBLAS_LIB_PATH = ./CLAPACK/BLAS/WRAP
F2C_LIB_PATH = ./CLAPACK/F2CLIBS
LINUX_LIBS_PATH = ./CLAPACK

F2C_LIB = libf2c.a
BLAS_LIB = libcblaswr.a
LIN_BLAS_LIB = blas_LINUX.a
LIN_LAPACK_LIB = lapack_LINUX.a
#LIN_OTHER_LIB = tmglib_LINUX.a

NVCC = $(CUDA_BIN_PATH)/nvcc

LINK_FLAGS = -link -v -o test -L/usr/lib-llapack-lblas-lg2c-lm-lstdc++ -I$(CUDA_INC_PATH) -I$(OTHER_INCS_PATH1) -L$(F2C_LIB_PATH)-l$(F2C_LIB) -L$(CBLAS_LIB_PATH)-l$(BLAS_LIB) -L$(LINUX_LIBS_PATH)-l$(LIN_LAPACK_LIB) -L$(LINUX_LIBS_PATH )-l$(LIN_BLAS_LIB)

COMPILE_FLAGS = -c -v -g -use_fast_math -O0 -L/usr/lib-llapack-lblas-lg2c-lm-lstdc++ -I$(CUDA_INC_PATH) -I$(OTHER_INCS_PATH1) -L$(CUDA_LIB_PATH) -L$(CBLAS_LIB_PATH) -L$(F2C_LIB_PATH) -L$(LINUX_LIBS_PATH)-l$(LIN_LAPACK_LIB) -L$(LINUX_LIBS_PATH )-l$(LIN_BLAS_LIB) -L$(LINUX_LIBS_PATH)-l$(LIN_OTHER_LIB)


build: spotrftest.o
$(NVCC) $(LINK_FLAGS) spotrftest.o

spotrftest.o: spotrftest.c
$(NVCC) $(COMPILE_FLAGS) spotrftest.c

clean:
rm test spotrf.o spotrftest.o

Thanks a million
the-shifter
 
Posts: 7
Joined: Mon Apr 14, 2008 2:25 am

Postby Julie » Wed Apr 16, 2008 10:37 am

What gives
Code: Select all
nm lapack_LINUX.a  | grep -i sportf



Could you put the path in "hard" to see the libraries clearly
gcc -c /CLAPACK/lapack_LINUX.a /CLAPACK/blas_LINUX.a
You do not need Cuda at the moment

Thanks
Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby the-shifter » Thu Apr 17, 2008 1:11 am

Hi Julie

I tried the nm command before as you typed, it just executes but gives nothing as output, so I tried only "nm lapack_LINUX.a" that gave me this output for the spotrf function part:

spotrf.o:
0000000000000010 d c__1.1734
0000000000000004 d c_b13.1736
0000000000000000 d c_b14.1737
0000000000000008 d c_n1.1735
U ilaenv_
0000000000000018 b j.1744
0000000000000010 b jb.1745
U lsame_
0000000000000008 b nb.1746
U sgemm_
U spotf2_
0000000000000000 T spotrf_
U ssyrk_
U strsm_
0000000000000000 b upper.1764
U xerbla_

so I guess that means its defined.

Also, I have already tried the hard coded path, it doesn't make a difference.

and I have removed all the CUDA related stuff for simplicity, but again same error.

What do you think I should try next?

Thanks
the-shifter
 
Posts: 7
Joined: Mon Apr 14, 2008 2:25 am

Postby Julie » Thu Apr 17, 2008 7:22 pm

yep sorry I had a spelling mistake in my command: we are looking for SPOTRF, not SPORTF

I will advice you to go with the LAPACK Fortran Library and call it from C.
CLAPACK is intended for machine without a C compiler.

Code: Select all
//#include "inputs.h"
#include <stdio.h>
#include <time.h>

extern spotrf_(char *, int *, float *, int *, int *);

int main(void)
{
char uplo;
int n, lda, info;
float a[4]={1.0, 0.0, 2.0, 0.0};;

n=2;
uplo='U';
lda=2;
/* SPOTRF */
spotrf_(&uplo, &n, a, &lda, &info);
printf("INFO = %d\n", info);

}


To get that compiled and linked with the ref blas:
COMPILATION (with C compiler)
Code: Select all
gcc -c spotrftest.c
LINK (with Fortran compiler)
Code: Select all
gfortran spotrftest.o - o spotrftest $(PATH to Fortran LAPACK)/lapack_LINUX.a $(PATH to Fortran LAPACK)/blas_LINUX.a


hope it helps
Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby the-shifter » Thu Apr 17, 2008 10:05 pm

The problem is that I must use CLAPACK since I will be using CUDA to multi-thread the original C source code, if I use original fortran LAPACK, then I ll have to translate all the Fortran code to C code again, while we already have a ready C LAPACK version...so no point in that.

Do you think the problem might be from the setting of my Makefile.inc or they way I compile and link the BLAS library to CLAPACK...or since it already passes all the included library tests and the nm command...then it means there is no problems with previous steps and that its ready to use...?

Also, if you have any other suggestions to try out...please advise.

Thanks again
the-shifter
 
Posts: 7
Joined: Mon Apr 14, 2008 2:25 am

Postby Julie » Thu Apr 17, 2008 11:04 pm

ok,
a big problem is that at the moment CLAPACK 3.1.1 is not thread safe.
We are working to have a thread safe release anytime soon.
I can help you solve your linking problem but you will not be able to run the code "thread safe".
If needed I can put you in contact with our teammate that is taking care of that.
Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby the-shifter » Thu Apr 17, 2008 11:59 pm

Its ok... I am as well still on research trying things out and am not expecting total robustness.
So if you can help me with the linking that will be great.
Thanks
the-shifter
 
Posts: 7
Joined: Mon Apr 14, 2008 2:25 am

Postby Ankur » Fri Apr 18, 2008 3:27 pm

Hello,

I am also facing a similar problem of undefined reference to sgglse_

Did anyone figure out a solution to this issue?

Thanks,
-Ankur
Ankur
 
Posts: 5
Joined: Fri Apr 18, 2008 3:24 pm

Postby Julie » Fri Apr 18, 2008 4:40 pm

here is a little code:
Code: Select all
//#include "inputs.h"
#include <stdio.h>
#include <time.h>
#include "f2c.h"
#include "clapack.h"

int main(void)
{
char uplo;
integer n, lda, info;
real a[4]= { 2.0, 1.0, 1.0, 2.0}

n=2;
uplo='U';
lda=2;
/* SPOTRF
 int spotrf_(char *uplo, integer *n, real *a, integer *lda, integer *info); */

spotrf_(&uplo, &n, a, &lda, &info);
printf("INFO = %d\n", info);

}


and the makefile associated
Code: Select all
#       
# Makefile for building a program that calls a routine from
# the CLAPACK Library
#
#

CC = gcc
ROOTPATH = /Users/julie/Documents/Boulot/Clapack/CLAPACK-3.1.1-NETLIB/CLAPACK-3.1.1

INCDIRS = -I$(ROOTPATH)/INCLUDE
F2CDIR  = $(ROOTPATH)/F2CLIBS
BLASLIB = $(ROOTPATH)/blas_LINUX.a
//BLASWRAP = $(ROOTPATH)/libcblaswr.a
//BLASLIB = -framework vecLib

LDLIBS  = $(BLASWRAP) $(ROOTPATH)/lapack_LINUX.a  $(BLASLIB)  $(F2CDIR)/libf2c.a -lm


spotrftest: spotrftest.c
   $(CC) spotrftest.c  $(INCDIRS) $(LDLIBS) -o spotrftest
   
clean:
   rm -f spotrftest.o spotrftest



For info CLAPACK has been compiled with the default make.inc (make.inc.example)

Hope it helps both of you to solve your problem.
Julie
Last edited by Julie on Mon Apr 21, 2008 1:03 pm, edited 1 time in total.
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby Ankur » Fri Apr 18, 2008 6:19 pm

Hi Julie,

Thanks for your quick response. I am following your directions, however I still have that issue. Let me post relevant sections of my makefile and code.

Exact link error:
Code: Select all
c++  -o bodyTracker bodytrackergui.o main.o moc_bodytrackergui.o   -L/home/adatta/CLAPACK-3.1.1 -L/usr/lib64 -L/opt/intel/ipp/5.3.2.068/em64t/sharedlib -L/usr/local/lib -L/usr/lib64/qt4 -lQtGui -L/usr/lib64 -L/usr/lib64/qt4 -L/usr/lib -lpng -lSM -lICE -lXrender -lXrandr -lXfixes -lXcursor -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lguide /home/adatta/CLAPACK-3.1.1/liblapack_LINUX.a /home/adatta/CLAPACK-3.1.1/libblas_LINUX.a -lcxcore -lcv -lhighgui -lcvaux -lippsem64t -lippcoreem64t -lrt -ldl -ldc1394 -lraw1394 -lpthread  -lz -lm /home/adatta/CLAPACK-3.1.1/libf2c.a
bodytrackergui.o: In function `bodyTrackerGUI::solveLS_Constrained(CvMat*, CvMat*, CvMat*)':
/home/adatta/workspace/SinglePrecCode/bodytrackergui.cpp:1152: undefined reference to `sgglse_(long*, long*, long*, float*, long*, float*, long*, float*, float*, float*, float*, long*, long*)'
collect2: ld returned 1 exit status
make: *** [bodyTracker] Error 1


Makefile:
Code: Select all

 INCPATH       = -I/home/adatta/CLAPACK-3.1.1/INCLUDE -I/opt/intel/ipp/5.3.2.068/em64t/include -I/usr/local/include/opencv -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr    /include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I.     
                                                                                               
LINK          = c++                                                                                                                                                                             
LFLAGS        =                                                                                                                                                                                 
ROOTPATH      = /home/adatta/CLAPACK-3.1.1                                                                                                                                                       
LIBS          = $(SUBLIBS) -L/home/adatta/CLAPACK-3.1.1 -L/usr/lib64 -L/opt/intel/ipp/5.3.2.068/em64t/sharedlib -L/usr/local/lib -L/usr/lib64/qt4 -lQtGui -L/usr/lib64 -L/usr/lib64/qt4 -L/usr/li    b -lpng -lSM -lICE -lXrender -lXrandr -lXfixes -lXcursor -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lguide $(ROOTPATH)/liblapack_LINUX.a $(ROOTPATH)/libblas_LINUX.a -lcxcore -lcv -lhighgui     -lcvaux -lippsem64t -lippcoreem64t -lrt -ldl -ldc1394 -lraw1394 -lpthread  -lz -lm $(ROOTPATH)/libf2c.a     


How I call it in c++ file:

Code: Select all
 sgglse_((integer*)&m, (integer*)&n, (integer*)&nn, (real*)AA_S, (integer*)&m, (real*)CC_S, (integer*)&nn, (real*)BB_S, (real*)ZA2_S, (real*)xhat2, (real*)D2_S, (integer*)&k2, (integer*)&i);


I have included the following
Code: Select all
#include "f2c.h"                                                                                                                                                                                  #include "clapack.h"


What do you recommend as next?

Thanks,
-Ankur
Ankur
 
Posts: 5
Joined: Fri Apr 18, 2008 3:24 pm

Postby Julie » Fri Apr 18, 2008 6:34 pm

Ankur,
- try to compile my little code first even if it is C.
(just to persuade yourself that everything is fine)

- here is something strange in what you have...
from clapack.h
Code: Select all
/* Subroutine */ int sgglse_(integer *m, integer *n, integer *p, real *a,
        integer *lda, real *b, integer *ldb, real *c__, real *d__, real *x,
        real *work, integer *lwork, integer *info);

from your error
Code: Select all
undefined reference to `sgglse_(long*, long*, long*, float*,

Looks like there is a mix between integer and long somewhere...

This could be something to explore.
Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby Ankur » Fri Apr 18, 2008 6:51 pm

Julie,

Sure let me try that now.

To answer the second question that you raised, I found the following line at the top of f2c.h:

typedef long int integer;

-Ankur
Ankur
 
Posts: 5
Joined: Fri Apr 18, 2008 3:24 pm

Postby Ankur » Fri Apr 18, 2008 7:46 pm

Julie,

So that program that you had posted compiles and runs. I am getting INFO=0 answer.

Makefile and code are as follows:

Code: Select all
 6 CC = cc                                                                                                                                                                                           
 7 ROOTPATH = /home/adatta/CLAPACK-3.1.1                                                                                                                                                             
 8                                                                                                                                                                                                   
 9 INCDIRS = -I$(ROOTPATH)/INCLUDE                                                                                                                                                                   10 F2CDIR  = $(ROOTPATH)/F2CLIBS                                                                                                                                                                     
11 BLASLIB = $(ROOTPATH)/libblas_LINUX.a                                                                                                                                                             
12                                                                                                                                                                                                   
13 LDLIBS  = $(ROOTPATH)/liblapack_LINUX.a  $(BLASLIB)  $(F2CDIR)/libf2c.a -lm                                                                                                                       
14                                                                                                                                                                                                   
15 spotrftest: spotrftest.o                                                                                                                                                                          16     $(CC) -o spotrftest  $(INCDIRS) spotrftest.o $(LDLIBS)                                                                                                                                       
17                                                                                                                                                                                                   
18 spotrftest.o: spotrftest.c                                                                                                                                                                       
19     $(CC) $(CFLAGS) $(INCDIRS) -c spotrftest.c                                                                                                                                                   
20                                                                                                                                                                                                   
21 clean:                                                                                                                                                                                           
22     rm -f spotrftest.o spotrftest                 


Program code

Code: Select all
 2 #include <stdio.h>                                                                                                                                                                               
 3 #include <time.h>                                                                                                                                                                                 
 4 #include "f2c.h"                                                                                                                                                                                 
 5 #include "clapack.h"                                                                                                                                                                             
 6                                                                                                                                                                                                   
 7 int main(void)                                                                                                                                                                                   
 8 {                                                                                                                                                                                                  9 char uplo;                                                                                                                                                                                       
10 integer n, lda, info;                                                                                                                                                                             
11 real a[4]={20.0, 10.0, 1.0, 1.0};                                                                                                                                                                 
12                                                                                                                                                                                                   
13 n=2;                                                                                                                                                                                             
14 uplo='U';                                                                                                                                                                                         15 lda=2;                                                                                                                                                                                           
16 /* SPOTRF                                                                                                                                                                                         
17  int spotrf_(char *uplo, integer *n, real *a, integer *lda, integer *info); */                                                                                                                   
18                                                                                                                                                                                                   
19  spotrf_(&uplo, &n, a, &lda, &info);                                                                                                                                                             
20  printf("INFO = %d\n", info);                                                                                                                                                                     
21                                                                                                                                                                                                   
22  }                                 


Something small is wrong somewhere in my makefile or my code. I am trying to see where this example differs from my earlier problem.

Thanks,
-Ankur
Ankur
 
Posts: 5
Joined: Fri Apr 18, 2008 3:24 pm

Problem Solved

Postby Ankur » Sat Apr 19, 2008 1:36 am

Hi Julie,

Thanks for all your help. I have been able to solve the problem.

This what I did, so others can follow. I got atlas for my machine and through that I also got lapack and blas libraries for my machine.

Now, my makefile contains path to the atlas libraries directory and -llapack and -lblas.

In my code, I only include "f2c.h".

I also had to define extern "C" sgglse_(...) style function prototype since I was calling lapack from c++. All the inputs to the function were either int or float.

I was able to link the program using this procedure.

Thanks again for taking out time to look through my questions.
-Ankur
Ankur
 
Posts: 5
Joined: Fri Apr 18, 2008 3:24 pm

Postby the-shifter » Mon Apr 21, 2008 4:19 am

Thanks Julie...I passed my linking too.
One more question though...in your code you suggested an order 2 matrix, I would like to go bigger and work on variable matrices lengths.
So do you happen to have a sample algorithm that generates real symmetric positive definite matrices? or if not, can you point out from the test files source code the part which generates this matrix?

Thank you
Maho
the-shifter
 
Posts: 7
Joined: Mon Apr 14, 2008 2:25 am

Next

Return to User Discussion

Who is online

Users browsing this forum: No registered users and 3 guests