0

I am trying to use an external library called "decomp_2d" with my fortran program. I have an environment variable declared "DECOMP2D" which points to the directory where "decomp_2d" is located. This directory has the following structure:

[k00603@fe01p03 2decomp_fft]$ls
doc  examples  include  lib  Makefile  README  src
[k00603@fe01p03 2decomp_fft]$ls lib/
lib2decomp_fft.a  Makefile
[k00603@fe01p03 2decomp_fft]$ls include/
decomp_2d_fft.mod  decomp_2d_io.mod  decomp_2d.mod  glassman.mod

In another directory I am trying to call a program which uses the subroutines of this library. But when I am doing this, I am getting a compile time error. I am attaching a minimal fortran code which I am using and the Makefile I am using to compile. It is a Fujitsu machine and they have there own fortran compiler which I am using to compile:

The program:

  program   Sora_v71

! Use the external library
  use decomp_2d

  integer n

  call decomp_2d_init(n,n,n,n,n)

  stop
  end

Makefile:

# Lines included for using the 2decomp libraries
INC_2DECOMP = -I$(DECOMP2D)/include/
L2DECOMP = -L$(DECOMP2D)/lib/ -l2decomp_fft

## ------------------------------------------------------
RM        =  rm
SRCDIR    = .
LIBDIR    = .
BIN       = binary
OBJS      = main.o 

## -------------------------------------------------------
mpifrtpx=$(shell which mpifrtpx)
FC=$(mpifrtpx)

FFLAGS   = $(F90FLAG) $(INC_2DECOMP) 
LFLAGS   = $(F90FLAG) -L$(LIBDIR) $(L2DECOMP)

## -------------------------------------------------------
all: $(BIN)

$(BIN): $(OBJS)
    @echo Linking $(BIN) .....
    $(FC) $(LFLAGS) -o $@ $(OBJS)

.f.o:
@echo Compiling $*.f
$(FC) $(FFLAGS) -c $(SRCDIR)/$*.f

clean:
@echo 'Cleaning .....'
$(RM) -f core *.o *~ *.L *.O $(BIN) $(SIZE_FILE)

When I am typing "make" I am getting the following error:

[k00603@fe01p04 test]$make
Compiling main.f
/opt/FJSVtclang/GM-1.2.0-11/bin/mpifrtpx  -I/home/hp120242/k00603/2decomp_fft//include/ -c ./main.f
Linking binary .....
/opt/FJSVtclang/GM-1.2.0-11/bin/mpifrtpx  -L. -L/home/hp120242/k00603/2decomp_fft//lib/ -l2decomp_fft -o binary main.o 
main.o: In function `MAIN__':
main.f:(.text+0x4c): undefined reference to `decomp_2d.decomp_2d_init_'
main.o:(.data+0x0): undefined reference to `decomp_2d.decomp_2d_init_'
make: *** [binary] Error 1

Any ideas?

wp78de
  • 18,207
  • 7
  • 43
  • 71
Pradeep Kumar Jha
  • 877
  • 4
  • 15
  • 30
  • What operating systém and compiler do you use? Is this a Fujitsu vector machine? Is the path behind -L correct? – Vladimir F Героям слава Feb 20 '13 at 07:26
  • It is a Fujitsu scalar machine. And yes, the path is correct: [k00603@fe01p03 2decomp_fft]$pwd /home/hp120242/k00603/2decomp_fft [k00603@fe01p03 2decomp_fft]$echo $DECOMP2D /home/hp120242/k00603/2decomp_fft/ – Pradeep Kumar Jha Feb 20 '13 at 07:38
  • the operating system is Linux and compiler is mpifrtpx – Pradeep Kumar Jha Feb 20 '13 at 08:11
  • 1
    Perhaps the compilation order is wrong? Because of the `use` statement the file with the module decomp_2d has to be compiled before main.f. I suggest trying to write a file with plain shell command to do the compilation and getting that to work, then to work on a make file if you still want that. This will separate `make` issues from "how to compile this program" issues. – M. S. B. Feb 20 '13 at 09:05

1 Answers1

2

With some linkers the order of the libraries in the linking command matters. Generally they have to come after the object files that reference them. Try to switch $(LFLAGS) and $(OBJS) in the link command.

eriktous
  • 6,569
  • 2
  • 25
  • 35