You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下用gfortran编译Fortran项目时BLAS/LAPACK符号链接错误

Windows下gfortran+OpenBLAS构建Elmer时BLAS符号未定义的链接问题

环境信息

  • 操作系统:Windows 10
  • 编译器:gfortran 10.2.0
  • 线性代数库:OpenBLAS 0.3.15
  • 目标软件:Elmer有限元9.0版本(代码分支:wip/windows)

问题现象

构建Elmer的共享库时遭遇链接错误,提示无法解析snrm2_、sdot_、dnrm2_等BLAS/LAPACK符号引用。

CMake配置与链接命令

CMake配置中通过find_package(BLAS)和find_package(LAPACK)自动查找OpenBLAS,并将其链接到Elmer求解器的共享库。

CMake生成的链接命令如下:

/mingw64/bin/gfortran.exe -fallow-argument-mismatch -O2 -g -DNDEBUG -shared -o msys-fhuti.dll -Wl,-Bsymbolic -Wl,--out-implib,libfhuti.dll.a -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/fhuti.dir/huti_aux.F90.o CMakeFiles/fhuti.dir/huti_bicgstab_2.F90.o etc.. -lffi -lopenblas -lgfortran -lm

错误信息

简洁错误输出

undefined reference to `snrm2_'
undefined reference to `sdot_'
undefined reference to `dnrm2_'
etc...

完整错误输出

Linking Fortran shared library msys-fhuti.dll

cd "/c/Users/Foo/OneDrive - Bar/Desktop/Elmer/elmerfem/build/fhutiter/src" && /usr/bin/cmake.exe -E cmake_link_script CMakeFiles/fhuti.dir/link.txt --verbose=1

/mingw64/bin/gfortran.exe -fallow-argument-mismatch -O2 -g -DNDEBUG -shared -Wl,--enable-auto-import -o msys-fhuti.dll -Wl,--out-implib,libfhuti.dll.a -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/fhuti.dir/huti_aux.F90.o CMakeFiles/fhuti.dir/huti_bicgstab_2.F90.o CMakeFiles/fhuti.dir/huti_bicgstab.F90.o CMakeFiles/fhuti.dir/huti_cg.F90.o CMakeFiles/fhuti.dir/huti_cgs.F90.o CMakeFiles/fhuti.dir/huti_gmres.F90.o CMakeFiles/fhuti.dir/huti_qmr.F90.o CMakeFiles/fhuti.dir/huti_tfqmr.F90.o CMakeFiles/fhuti.dir/huti_interfaces.F90.o CMakeFiles/fhuti.dir/huti_sfe.F90.o

C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/fhuti.dir/huti_sfe.F90.o:huti_sfe.F90:(.rdata$.refptr.snrm2_[.refptr.snrm2_]+0x0): undefined reference to `snrm2_'

C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/fhuti.dir/huti_sfe.F90.o:huti_sfe.F90:(.rdata$.refptr.sdot_[.refptr.sdot_]+0x0): undefined reference to `sdot_'

C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/fhuti.dir/huti_sfe.F90.o:huti_sfe.F90:(.rdata$.refptr.dnrm2_[.refptr.dnrm2_]+0x0): undefined reference to `dnrm2_'

C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/fhuti.dir/huti_sfe.F90.o:huti_sfe.F90:(.rdata$.refptr.ddot_[.refptr.ddot_]+0x0): undefined reference to `ddot_'

C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/fhuti.dir/huti_sfe.F90.o:huti_sfe.F90:(.rdata$.refptr.scnrm2_[.refptr.scnrm2_]+0x0): undefined reference to `scnrm2_'

C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/fhuti.dir/huti_sfe.F90.o:huti_sfe.F90:(.rdata$.refptr.cdotc_[.refptr.cdotc_]+0x0): undefined reference to `cdotc_'

C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/fhuti.dir/huti_sfe.F90.o:huti_sfe.F90:(.rdata$.refptr.dznrm2_[.refptr.dznrm2_]+0x0): undefined reference to `dznrm2_'

C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/fhuti.dir/huti_sfe.F90.o:huti_sfe.F90:(.rdata$.refptr.zdotc_[.refptr.zdotc_]+0x0): undefined reference to `zdotc_'

collect2.exe: error: ld returned 1 exit status

make[2]: *** [fhutiter/src/CMakeFiles/fhuti.dir/build.make:234: fhutiter/src/msys-fhuti.dll] Error 1

make[2]: Leaving directory '/c/Users/Foo/OneDrive - Bar/Desktop/Elmer/elmerfem/build'

make[1]: *** [CMakeFiles/Makefile2:16866: fhutiter/src/CMakeFiles/fhuti.dir/all] Error 2

make[1]: Leaving directory '/c/Users/Foo/OneDrive - Bar/Desktop/Elmer/elmerfem/build'

make: *** [Makefile:169: all] Error 2

已尝试的解决方法

  • 手动编译链接验证OpenBLAS库功能正常
  • 改用target_link_libraries()显式链接库,替代find_package()自动查找
  • 测试不同链接标志组合,如-Wl,-Bsymbolic
  • 确认gfortran版本、OpenBLAS架构与系统匹配

求助问题

如何解决Windows下使用gfortran和OpenBLAS时的上述链接错误?OpenBLAS符号解析失败的可能原因有哪些?


内容的提问来源于stack exchange,提问作者Foad S. Farimani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 22:37:32