【问题标题】:Library linkage in makefile using gfortran使用 gfortran 的 makefile 中的库链接
【发布时间】:2013-10-22 19:01:01
【问题描述】:

我有一个 fortran 代码 (pardiso_1.f),它需要编译一些库(BLAS、lapack 和 Pardiso 库)。当我尝试编译它时,我会在编译之前链接库,并在 linux 终端中写下这一行:

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

而且效果很好。

但是我必须使用 makefile 运行代码。我在编写 makefile 方面很陌生,我不知道如何进行链接。我已经写了这个makefile。谁能帮我找出问题所在?

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/PS2/

#### Series of libraries
LIBRARIES= -llapack -lblas -lpthread -lm -lpardiso412-GNU430-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)

错误是:

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

【问题讨论】:

    标签: linux makefile fortran gfortran


    【解决方案1】:

    您的 makefile 不包含命令行的 -L/home/behnam/Pardiso 部分。

    【讨论】:

    • /home/behnam/PS2/ 与 /home/behnam/Pardiso 相同
    • @behnamm:看看你的错误代码。注意它是怎么说的,gfortran -fopenmp pardiso_1.f -o pardiso_1,不包括-L/home/behnam/PS2
    【解决方案2】:

    PROGRAMS 的规则不包含包含库调用的配方。我想你想要类似 nlace 规则的东西,但现在,make 不会调用你的任何 -L 开关作为其操作的一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      • 2012-09-12
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多