繁体   English   中英

f2py 和 gfortran 的编译错误:对“main”的未定义引用

[英]compilation error with f2py and gfortran: undefined reference to `main'

我最近开始使用 f2py 和 python2.7 来处理与 Fortran 中的海洋模型 (ROMS) 相关的一些代码。 我的工作站细节是 Ubuntu 16.04,带有 python2.7、anaconda2 和 gfortran。 我也安装了 netcdf 和 hdf5 库。

makefile 中的指令如下(在一行中):

$(F2PY) --fcompiler=gfortran --f90flags=$(F2PY_F90_FLAG) $(F2PY_LIB) $(F2PY_INCLUDE) $(OBJF2PY) -m -c 脚本 pyscrip.f90

在哪里:

  • F2PY链接到/bin目录中的 f2py 编译器。
  • OBJF2PY是使用 f2py 编译的一组目标文件(所有相关的源文件都在目录中)。
  • F2PY_INCLUDE是包含路径(包含 netcdf.inc 和 netcdf.mod)
  • -L${LIBDIR} -lnetcdf -lnetcdff -lhdf5 -lhdf5_hl - 是库路径,链接到 netcdf 和 hdf5 库文件。
  • F2PY_F90_FLAG = '-g -fdefault-real-8 -ffixed-form -O2 -fPIC -m64 -shared ' - 链接到 f2py 的编译器标志。

在编译过程中,我收到一个错误:

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function _start: (.text+0x20): undefined reference to 'main' collect2: error: ld returned 1 exit status

我不明白为什么会出现这个错误。 指令的顺序是否正确? 它与编译器标志有关吗? 是否有代码需要的任何其他包含文件(netcdf.inc 除外)或任何其他库(netcdf 和 hdf5 库除外)?

答案在GitHub 上给出,是将-shared选项添加到LDFLAGS环境变量中。 在运行f2py之前尝试LDFLAGS="-shared $LDFLAGS"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM