Undefined reference to LAPACK and BLAS subroutines

不羁的心 提交于 2019-11-28 14:26:10
Phil Hasnip

It looks like you might not have linked to the libraries. Try:

gfortran -o test test.f03 -llapack -lblas

This causes the linker (the program which joins all the program parts together; usually called "ld" on UNIX) to include the library code for the LAPACK call (or a dynamic link to it) in your program.

If the result of the above line is "cannot find -llapack" or similar, there are two common problems:

  1. Libraries can be "shared" (names ending ".so") or "static" (names ending ".a"); the linker will look for the shared one, so if you only have the static one you should add "-static" before the library link:

    gfortran -o test test.f03 -static -llapack -lblas
    

    This will also make it look for the static version of BLAS; if you need the shared version, add "-shared" in front of the "-lblas":

    gfortran -o test test.f03 -static -llapack -shared -lblas

    You might find this page helpful.

  2. The linker isn't looking in the right directory for the libraries. You need to locate the actual library (called something like "liblapack.so" or "liblapack.a") and make sure the directory it's in is included in the directories the linker looks in, e.g. to get it to look in "/mylibs/maths" as well:

    gfortran -o test test.f03 -L/mylibs/maths -llapack -lblas
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!