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

Using LAPACK and BLAS with make...

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

Using LAPACK and BLAS with make...

Postby stockhausen » Wed Sep 05, 2007 5:11 pm

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.
stockhausen
 
Posts: 7
Joined: Tue Aug 21, 2007 5:19 pm

Postby Julie » Wed Sep 05, 2007 5:18 pm

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
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby stockhausen » Wed Sep 05, 2007 5:38 pm

Thanks very much Julien! You have saved me once again!
stockhausen
 
Posts: 7
Joined: Tue Aug 21, 2007 5:19 pm

Postby Julien Langou » Wed Sep 05, 2007 6:03 pm

That was Julie this time, not Julien.
Julien Langou
 
Posts: 835
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Postby stockhausen » Wed Sep 05, 2007 6:18 pm

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.
stockhausen
 
Posts: 7
Joined: Tue Aug 21, 2007 5:19 pm

Postby Julie » Wed Sep 05, 2007 6:48 pm

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
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 4 guests