我能够使用这些命令正常编译fortran程序:
ifort -O2 -I/work/GSI/include -c create_upperair.f90
ifort -o create_upperair.exe -O2 create_upperair.o -L/work/GSI/lib -lbufr
我正在尝试使用相同的fortran程序,但将其编译为python共享对象文件,以便我可以从python脚本调用此子例程。但是f2py命令给了我一些问题。
这是我目前使用的命令:
f2py -c -L/work/GSI/lib -lbufr -I/work/GSI/include --f90flags=-O2 --fcompiler=ifort -m create_upperair create_upperair.f90
但是,在f2py命令的末尾打印出错误,如:
ld: /work/GSI/lib/libbufr.a(closbf.o): relocation R_X86_64_32S against `nulbfr_' can not be used when making a shared object: recompile with -fPIC
我试图添加--f90flags =" -O2 -fPIC"我的f2py命令,但它也没有工作。任何有关这个问题的方向的想法都将非常感激。
这是f2py结束时的完整错误(请注意,为简单起见,我在上面更改了一些目录名称):
ifort:f90: prepbufr_encode_upperair.f90
/glade/apps/opt/modulefiles/ys/cmpwrappers/ifort -shared -shared -nofor_main /tmp/tmpzYKBY5/tmp/tmpzYKBY5/src.linux-x86_64-2.7/prepbufr_encode_upperairmodule.o /tmp/tmpzYKBY5/tmp/tmpzYKBY5/src.linux-x86_64-2.7/fortranobject.o /tmp/tmpzYKBY5/prepbufr_encode_upperair.o - L/glade/p/work/sdegelia/softwares/comGSI_v3.3/lib -L/glade/apps/opt/python/2.7.7/gnu-westmere/4.8.2/lib -lbufr_i4r8 -lpython2.7 -o ./prepbufr_encode_upperair.so
ld: /glade/p/work/sdegelia/softwares/comGSI_v3.3/lib/libbufr_i4r8.a(closbf.o): relocation R_X86_64_32S against `nulbfr_' can not be used when making a shared object; recompile with -fPIC
/glade/p/work/sdegelia/softwares/comGSI_v3.3/lib/libbufr_i4r8.a: could not read symbols: Bad value
ld: /glade/p/work/sdegelia/softwares/comGSI_v3.3/lib/libbufr_i4r8.a(closbf.o): relocation R_X86_64_32S against `nulbfr_' can not be used when making a shared object; recompile with -fPIC
/glade/p/work/sdegelia/softwares/comGSI_v3.3/lib/libbufr_i4r8.a: could not read symbols: Bad value
error: Command "/glade/apps/opt/modulefiles/ys/cmpwrappers/ifort -shared -shared -nofor_main /tmp/tmpzYKBY5/tmp/tmpzYKBY5/src.linux-x86_64-2.7/prepbufr_encode_upperairmodule.o /tmp/tmpzYKBY5/tmp/tmpzYKBY5/src.linux-x86_64-2.7/fortranobject.o /tmp/tmpzYKBY5/prepbufr_encode_upperair.o -L/glade/p/work/sdegelia/softwares/comGSI_v3.3/lib -L/glade/apps/opt/python/2.7.7/gnu-westmere/4.8.2/lib -lbufr_i4r8 -lpython2.7 -o ./prepbufr_encode_upperair.so" failed with exit status 1