我正在尝试使用gcc与ubuntu机器上的gfortran包编译f90代码。不幸的是,在运行编译器时,我不断得到未定义的引用错误。
我按如下方式调用编译器:
gfortran -o gauss Guass1d.f90 linalg.f90
或者,我尝试为linalg.f90创建目标文件,然后使用以下内容:
gfortran -o guass Guass1d.f90 linalg.mod (tried with linalg.o as well)
这些都不奏效。代码来自位于https://sites.google.com/site/varga1kalmanbook/computer-codes/part-i/chapter-1/variational-method-shifted-gaussians的书籍(位于页面底部)
我确信这只是我编写代码的问题,但由于缺乏对fortran的经验,我无法指责它。
任何协助都会有很大的帮助!
答案 0 :(得分:7)
以下对我有用:
$ gfortran -O2 -c linalg.f90
$ gfortran -O2 gauss_1d_c.f90 linalg.o -o gauss -llapack -lblas
所以原因是linalg.f90使用LAPACK,因此你需要链接到LAPACK和BLAS。