Page 1 of 1

Using LAPACK and BLAS with make...

PostPosted: Wed Sep 05, 2007 5:11 pm
by stockhausen
Hello,

When I run my program from the command line I have no problems, with commands such as:

Code: Select all
gcc program.c -o program.exe -llapack -lblas


But when I try to compile using make, I have errors. My make file looks like this:

Code: Select all
project: program.o
   cc program.o -o project
program.o: program.c
   cc -c program.c -llapack -lblas


And then from the command line I enter: make -f makefile and I get the following type of erros:

Code: Select all
program.o:program.c:(.text+0x59a): undefined reference to `_cblas_dgemv'


Any ideas?

Thanks.

PostPosted: Wed Sep 05, 2007 5:18 pm
by Julie
stockhausen,
you are mixing the compilation ( -c ) and the linking sequence with all the objects and librairies.
Try:
Code: Select all
project: program.o
   cc program.o -o project -llapack -lblas
program.o: program.c
   cc -c program.c


For info, if your makefile is called Makefile, you just need to run : "make"
Julie

PostPosted: Wed Sep 05, 2007 5:38 pm
by stockhausen
Thanks very much Julien! You have saved me once again!

PostPosted: Wed Sep 05, 2007 6:03 pm
by Julien Langou
That was Julie this time, not Julien.

PostPosted: Wed Sep 05, 2007 6:18 pm
by stockhausen
Many apologies to Julie! But now I have another more general question. If I have multiple files that require lapack, would I proceed in make the following way:

Code: Select all
project: program1.o program2.o 
   cc program1.o program2.o -o project -llapack -lblas
program1.o: program1.c
   cc -c program1.c
program2.o: program2.c
   cc -c program2.c


Thanks again.

PostPosted: Wed Sep 05, 2007 6:48 pm
by Julie
The name of your files confuse me a little bit.

Here is a little Makefile if you have only ONE main (ie one program at the end: project)
Code: Select all
ALLOBJ=program1.o program2.o

project: $(ALLOBJ)
        gcc $<-o $@ -llapack -lblas

clean:
        rm -f *.o project

.c.o:
        gcc  -c $< -o $@

Here is another one if you have several mains ( ie 2 programs at the end: prog1 and prog2 that need both LAPACK and BLAS librairies)
make or make all will build all the programs : prog1 and prog2.
make prog1 will only build prog1
make prog2 will only build prog2
make clean will delete all the objects and programs
Code: Select all
OBJPROG1=program1.o
OBJPROG2=program2.o

all: prog1 prog2

prog1: $(OBJPROG1)
        gcc $< -o $@ -llapack -lblas

prog2: $(OBJPROG2)
        gcc $< -o $@ -llapack -lblas

clean:
        rm -f *.o prog1 prog2

.c.o:
        gcc  -c $< -o $@


Hope it helps.
If you need further documentation on Makefile, I am sure Google has a lot answers for you.
Julie