MacOS下gfortran编译Tlusty遇clang段错误及链接问题
编译Tlusty/Synspec时遇到的gfortran与clang冲突及链接错误问题
问题背景
我正在编译用于生成恒星大气模型和合成光谱的Tlusty与Synspec程序,按照相关指南要求,需使用gfortran编译并添加-mcmodel=large参数来分配更多内存。
使用-mcmodel=large参数时的编译错误
执行编译命令:
gfortran -fno-automatic -mcmodel=large -o tlusty.exe tlusty208.f
终端输出错误信息:
tlusty208.f:13753:72: 13753 | 230 A(I,J)=SUM | 1 Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 230 at (1) tlusty208.f:33348:72: 33348 | DO 230 J=1,NMU | 1 Warning: Fortran 2018 deleted feature: Shared DO termination label 230 at (1) clang: error: unable to execute command: Segmentation fault: 11 clang: error: clang integrated assembler command failed due to signal (use -v to see invocation) Apple clang version 17.0.0 (clang-1700.0.13.3) Target: x86_64-apple-darwin24.4.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
路径优先级检查
我已确认gfortran所在的/usr/local/bin路径在PATH中优先级高于clang所在的/usr/bin:
which gfortran # /usr/local/bin/gfortran which clang # /usr/bin/clang gfortran --version # GNU Fortran (Homebrew GCC 14.2.0_1) 14.2.0 # Copyright (C) 2024 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. clang --version # Apple clang version 17.0.0 (clang-1700.0.13.3) # Target: x86_64-apple-darwin24.4.0 # Thread model: posix # InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin echo $PATH # ... # /usr/local/bin: # ... # /usr/bin: # ...
不使用-mcmodel=large参数时的链接错误
执行编译命令:
gfortran -fno-automatic -O3 -o tlusty.exe tlusty208.f
终端输出链接错误:
tlusty208.f:13753:72: 13753 | 230 A(I,J)=SUM | 1 Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 230 at (1) tlusty208.f:33348:72: 33348 | DO 230 J=1,NMU | 1 Warning: Fortran 2018 deleted feature: Shared DO termination label 230 at (1) ld: fixup error (kind=x86_64_was_rip_got_load_elide_got) at '_divstr_.part.0'+0x8 from ccOcdtfu.o, 32-bit RIP-relative reference out of range (displacement=2279953044, max is +/-2GB), from 0x1000008C8 to 0x187E55B60 ('_straux_') final section layout: __PAGEZERO addr=0x000000000, size=0x100000000, fileOffset=0x00000000, fileSize=0x00000000 __TEXT addr=0x100000000, size=0x000159000, fileOffset=0x00000000, fileSize=0x00159000 __text addr=0x1000008c0, size=0x000115eee, fileOffset=0x000008c0 __text_startup addr=0x1001167b0, size=0x00000001f, fileOffset=0x001167b0 __stubs addr=0x1001167d0, size=0x000000108, fileOffset=0x001167d0 __cstring addr=0x1001168d8, size=0x00000000c, fileOffset=0x001168d8 __const addr=0x100116900, size=0x000036bdc, fileOffset=0x00116900 __eh_frame addr=0x10014d4e0, size=0x00000b798, fileOffset=0x0014d4e0 __DATA_CONST addr=0x100159000, size=0x000001000, fileOffset=0x00159000, fileSize=0x00001000 __got addr=0x100159000, size=0x0000001e8, fileOffset=0x00159000 __const addr=0x1001591e8, size=0x0000000d0, fileOffset=0x001591e8 __DATA addr=0x10015a000, size=0x0aaf05000, fileOffset=0x0015a000, fileSize=0x00017000 __data addr=0x10015a000, size=0x0000164a0, fileOffset=0x0015a000 __bss addr=0x1001704a0, size=0x01a6d19a0, fileOffset=0x00000000 __common addr=0x11a841e40, size=0x09081cc68, fileOffset=0x00000000 __LINKEDIT addr=0x1ab05f000, size=0x000021000, fileOffset=0x00171000, fileSize=0x000207d0 collect2: error: ld returned 1 exit status
已尝试的修复措施
发现gcc --version指向clang后,我在bash profile中添加了以下配置,但问题依旧:
alias gcc='/usr/local/bin/gcc-14' alias g++='/usr/local/bin/g++-14' alias gfortran='/usr/local/bin/gfortran-14' export FC=/usr/local/bin/gfortran-14 export F77=/usr/local/bin/gfortran-14
内容的提问来源于stack exchange,提问作者Gabriele
相关产品推荐
相关产品推荐

