2013-02-20 71 views
0

我正在嘗試在我的fortran程序中使用名爲「decomp_2d」的外部庫。我有一個聲明爲「DECOMP2D」的環境變量指向「decomp_2d」所在的目錄。此目錄具有以下結構:Fortran無法調用外部庫

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

在另一個目錄中,我試圖調用一個使用此庫的子例程的程序。但是當我這樣做時,我得到一個編譯時錯誤。我附上了我正在使用的最小Fortran代碼和我正在使用的Makefile進行編譯。這是富士通的機器,他們有這我使用編譯有自己的Fortran編譯器:

程序:

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 [email protected] $(OBJS) 

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

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

當我輸入「make」我我得到以下錯誤:

[[email protected] 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 

任何想法?

+0

你使用什麼操作系統和編譯器?這是富士通矢量機嗎?背後的路徑是否正確? – 2013-02-20 07:26:22

+0

這是一臺富士通標量機器。是的,路徑是正確的:k00603 @ fe01p03 2decomp_fft] $ PWD /家庭/ hp120242/k00603/2decomp_fft [k00603 @ fe01p03 2decomp_fft] $回聲$ DECOMP2D /家庭/ hp120242/k00603/2decomp_fft/ – jhaprade 2013-02-20 07:38:10

+0

操作系統是Linux和編譯器是mpifrtpx – jhaprade 2013-02-20 08:11:23

回答

2

對於一些鏈接器,鏈接命令中庫的順序很重要。一般來說,它們必須位於引用它們的對象文件之後。嘗試在鏈接命令中切換$(LFLAGS)$(OBJS)

+0

哦!解決了這個問題。非常感謝!! – jhaprade 2013-02-20 11:52:32

+0

在這種情況下接受答案。 – 2013-02-20 11:59:08