Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Library linkage in makefile using gfortran

Status
Not open for further replies.

behnam64

Programmer
Oct 22, 2013
12
US
I have a fortran code (pardiso_1.f) and it needs some libraries (BLAS, lapack and Pardiso libraries) to be compiled. When I try to compile it, I link libraries before compilation and I write this line in linux terminal:

gfortran pardiso_1.f -L/home/behnam/Pardiso -lpardiso412-GNU450-X86-64 -L/usr/lib -lblas -llapack -fopenmp

and it works perfectly.

However, I have to run the code using makefile. I am so new in writing makefiles and I do not know how to do the linkage. I have written this makefile. could anyone help me to find out what is wrong with that?

FC = gfortran
OPT = -O2
PROGRAMS = pardiso_1

all: $(PROGRAMS)
FFLAGS = -fopenmp

#### BLAS, LAPACK and PTHREAD libraries
LBLAS = /usr/lib/

###location of pardiso file
LIBMKL = /home/behnam/Pardiso/

#### Series of libraries
LIBRARIES= -llapack -lblas -lpthread -lm -lpardiso412-GNU450-X86-64

PATHFC = /usr/bin/

nlace: ${PATHFC}${FC} ${OPT} ${FFLAGS} -I${PROGRAMS} -o nlace.exe -L${LIBMKL} -lpardiso412-GNU430-X86-64 -L${LBLAS} ${LIBRARIES}


clean:
rm -f *.o *.exe fort.* *~ *.mod

veryclean: clean
rm -f *~ $(PROGRAMS)
The errors are:

behnam@meen-392430:~/testing$ make
make: Warning: File `Makefile' has modification time 23 s in the future
gfortran -fopenmp pardiso_1.f -o pardiso_1
/tmp/ccYNexaH.o: In function `MAIN__':
pardiso_1.f:(.text+0xb3): undefined reference to `pardisoinit_'
pardiso_1.f:(.text+0x2ae): undefined reference to `pardiso_chkmatrix_'
pardiso_1.f:(.text+0x36e): undefined reference to `pardiso_chkvec_'
pardiso_1.f:(.text+0x44c): undefined reference to `pardiso_printstats_'
pardiso_1.f:(.text+0x5ae): undefined reference to `pardiso_'
pardiso_1.f:(.text+0x860): undefined reference to `pardiso_'
pardiso_1.f:(.text+0xb78): undefined reference to `pardiso_'
pardiso_1.f:(.text+0xe00): undefined reference to `pardiso_'
collect2: ld returned 1 exit status
make: *** [pardiso_1] Error 1
 
It is probably linking the pardiso412-GNU430-X86-64 library from MKL instead of the pardiso412-GNU450-X86-64 from /usr/lib. Try removing

-L${LIBMKL} -lpardiso412-GNU430-X86-64
 
Hi xwb

Thanks for the answer but it is not the issue. Bot 450 and 430 can do that and the path is correct for them.
 
Just had another look, add -L/home/behnam/Pardiso before -lpardiso412-GNU450-X86-64
 
I did that and got the same error messages...
 
Change -I${PROGRAM} to ${PROGRAM}.

Also can you type make -n to see what make is actually trying to do. It should give you the command line it is trying to execute to build your program
 
I have not had deal with my make files in a while...the files I created a few years ago continue to work!

You should really read about 'make', it is not a trivial thing...it is certainly not another name for a bash shell, i.e., you do not simply type your commands...there is a LOT that happens in a makefile with few instructions...that's why make is so convenient.

At least take a look at a short tutorial and learn what a 'target' is, what a 'dependency' is, etc.

Here are a few things to watch out:

Make knows how to do basic compilation all on its own.
You can set a few preferences by setting standard variables like FC, FFLAGS
The default target is the first target in the make file ('all' in your case).
If you do not pick a target at the time of invoking make, the default target is executed.
Your desired 'nlace' target is NOT being executed, since you are simply typing 'make' at the command line...to get to nlace, you need to type 'make nlace' and THEN you will see that at least it will attempt to execute that command.
System command lines following a target clause need to start with a "tab" character!...and not just 4 blank spaces or whatever.





 
Thanks xwb

I changed that and still get the same errors:


behnam@meen-392430:~/testing$ make -n
gfortran -fopenmp pardiso_1.f -o pardiso_1
behnam@meen-392430:~/testing$ make clean
rm -f *.o *.exe fort.* *~ *.mod
behnam@meen-392430:~/testing$ make
gfortran -fopenmp pardiso_1.f -o pardiso_1
/tmp/ccYk27h1.o: In function `MAIN__':
pardiso_1.f:(.text+0xb3): undefined reference to `pardisoinit_'
pardiso_1.f:(.text+0x2ae): undefined reference to `pardiso_chkmatrix_'
pardiso_1.f:(.text+0x36e): undefined reference to `pardiso_chkvec_'
pardiso_1.f:(.text+0x44c): undefined reference to `pardiso_printstats_'
pardiso_1.f:(.text+0x5ae): undefined reference to `pardiso_'
pardiso_1.f:(.text+0x860): undefined reference to `pardiso_'
pardiso_1.f:(.text+0xb78): undefined reference to `pardiso_'
pardiso_1.f:(.text+0xe00): undefined reference to `pardiso_'
collect2: ld returned 1 exit status
make: *** [pardiso_1] Error 1
 
Thank you salgerman

Could you please refer me to some books or websites? I have already tried to find some related material but they are either too basic (like making some very simple makefiles) or too complicated.

By the way, I noted the your watch out list and almost all are examined and I am still working on the remaining items.
 
Post your make file but enclose it in "code" tags...the icon left of the yellow wrapped up gift with red bow along the top of the typing window.
 
Here is a sample make file
Code:
FC=gfortran
CFLAGS=-c
LFLAGS=
LIBS=
SRC=test.f90
OBJ=test.o
EXE=test.exe

def: $(EXE)

$(EXE): $(OBJ)
	$(FC) $(LFLAGS) -o $(EXE) $(OBJ)

%.o: %.f90
	$(FC) $(CFLAGS) -c $< -o $@
The first target requires the executable, so, make goes looking for a target with the same name.

The second target indicates how to produce an exe file out of object files; the system command line that follows says how to do so, ONCE the objects files exist....and, so, make goes looking for a target with the names of the object files needed...

It this case, it does not find explicit names, but finds...

The third target is a generic line that indicates how to produce *.o files out of *.f90 files.
 
Can you try this?
Code:
SRC=pardiso_1.f
EXE=nlace.exe

FC=/usr/bin/gfortran
FFLAGS=-O2 -fopenmp
INCLUDE=
IDIRS=
LIBS=-lblas -llapack -pthread -lm -lpardiso412-GNU450-X86-64
LDIRS=-L/usr/lib -L/home/behnam/Pardiso

all: $(EXE)

$(EXE): $(SRC)
	$(FC) $(LDIRS) $(FFLAGS) -o $(EXE) $(SRC) $(LIBS)
and from there, hopefully, you can start playing around depending on what you see make is trying to do
 
Great!!!!

Thank you. At first it gave me error (I had seen the error before) and then I substitute the libraries to the following:

LDIRS=-L/home/behnam/Pardiso LDIRS=-L/usr/lib

and then it worked perfectly.

Thank you very much!

Meanwhile, I study the web-page you introduced.
 
Sorry, to the following:

LDIRS=-L/home/behnam/Pardiso -L/usr/lib
 
and I changed this line, too:

LIBS=-lpardiso412-GNU450-X86-64 -lblas -llapack -pthread -lm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top