提问人:Foad S. Farimani 提问时间:8/23/2023 最后编辑:Foad S. Farimani 更新时间:8/23/2023 访问量:53
在 Windows 上使用 gfortran 构建 Fortran 项目时,带有 BLAS/LAPACK 符号(snrm2_、sdot_ 等)的链接器错误
Linker errors with BLAS/LAPACK symbols (snrm2_, sdot_, etc) when building Fortran project with gfortran on Windows
问:
我正在尝试在 Windows 10 上使用 gfortran 10.2.0 和 OpenBLAS 0.3.15 库构建 Elmer 有限元软件(9.0 版)。我在创建共享库时遇到链接器错误,它找不到对各种 BLAS/LAPACK 符号(如 snrm2_、sdot_、dnrm2_ 等)的引用。
在我的 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...
我试过:
- 已验证 OpenBLAS 库在使用 gfortran 手动编译/链接时是否正常工作
- 显式使用 target_link_libraries() 而不是 find_package() 的链接库
- 使用了链接器标志的不同组合,如 -Wl、-Bsymbolic
- 我检查了 gfortran 版本,OpenBLAS 架构与我的系统相匹配
但我仍然得到同样的未定义引用错误。在 Windows 上使用 gfortran 和 OpenBLAS 时如何解决此链接器问题?任何想法 OpenBLAS 符号的解析方式可能出了什么问题?
关于我如何解决这些 gfortran/BLAS 链接器错误的任何帮助或指示将不胜感激!
附言以下是完整的错误消息(此处也提到):
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
答: 暂无答案
评论