如何在含Makefile.am等的复杂构建系统中配置gfortran编译标志?
解决JModelica中Fortran77编译错误的配置修改方法
方法1:直接修改Assimulo的setup.py调用参数(最快生效)
查看你提供的build/Makefile里的build-python-packages目标,找到Assimulo的setup.py调用分支,直接追加额外Fortran编译标志:
找到非cygwin/mingw的分支:
*) \ python setup.py install --with_openmp=True --superlu-home=$(abs_builddir)/superlu_build/ --sundials-home=$(SUNDIALS_HOME) --sundials-with-superlu=True --blas-home=$(abs_builddir)/blas_install/ --lapack-home=$(abs_builddir)/lapack_install/ --prefix=$(assimulo_install_dir) ;;
修改为:
*) \ python setup.py install --with_openmp=True --superlu-home=$(abs_builddir)/superlu_build/ --sundials-home=$(SUNDIALS_HOME) --sundials-with-superlu=True --blas-home=$(abs_builddir)/blas_install/ --lapack-home=$(abs_builddir)/lapack_install/ --extra-fortran-flags="-ffixed-line-length-120" --prefix=$(assimulo_install_dir) ;;
如果cygwin/mingw分支也需要适配,给对应的setup.py调用同样加上--extra-fortran-flags="-ffixed-line-length-120"参数即可。
方法2:修改Assimulo的setup.py源码
打开external/Assimulo/setup.py,查找处理Fortran编译参数的部分:
- 找到类似
extra_f77_compile_args或extra_fortran_compile_args的列表变量,将'-ffixed-line-length-120'追加进去,示例:
extra_f77_compile_args = ['-Wall', '-g', '-ffixed-form', '-fno-second-underscore', '-fPIC', '-O3', '-funroll-loops', '-ffixed-line-length-120']
如果没有现成的参数列表,找到设置Fortran编译选项的代码块,手动添加该标志。
方法3:通过configure.ac全局设置
打开项目根目录的configure.ac,找到Fortran编译器初始化的代码段(比如AC_PROG_F77或AC_PROG_FC),在其后追加:
FFLAGS="$FFLAGS -ffixed-line-length-120" AM_FFLAGS="$AM_FFLAGS -ffixed-line-length-120"
修改完成后,需要重新运行autoreconf -i和./configure来生成新的Makefile。
方法4:修改Makefile.am
如果Assimulo对应目录下有Makefile.am文件(比如external/Assimulo/Makefile.am),添加或修改:
AM_FFLAGS = -ffixed-line-length-120
如果已有AM_FFLAGS或FFLAGS变量,将标志追加到现有内容后即可,修改后同样需要重新运行autoreconf和configure。
注意:优先选择方法1或2,因为编译命令直接来自Assimulo的setup.py,这两个方法更直接匹配当前问题场景。
内容的提问来源于stack exchange,提问作者Foad S. Farimani
相关产品推荐
相关产品推荐

