||
以彭国伦的《Fortran95程序设计》中ex0842m.f90和ex0842s.f90为例。
ex0842m.f90为主程序文件,ex0842s.f90为子程序文件。
!-------------ex0842m.f90-----------
program ex0842m
implicit none
call sub()
stop
end
!-------------------------------------------
!-----------ex0842s.f90---------------
subroutine sub()
implicit none
write(*,*) "This is subroutine"
return
end
!----------------------------------------
(1)利用ifort生成dll
ifort -o 123.so -shared -fpic ex0842s.f90
其中,123.so为生成的动态链接库
(2)此时若用ifort 123.so ex0842m.f90 去生成可执行文件,会有错误如下
ld: warning: libifport.so.5, needed by ifortcOP1IU.so, not found (try using -rpath or -rpath-link)
ld: warning: libifcore.so.5, needed by ifortcOP1IU.so, not found (try using -rpath or -rpath-link)
ld: warning: libimf.so, needed by ifortcOP1IU.so, not found (try using -rpath or -rpath-link)
ld: warning: libsvml.so, needed by ifortcOP1IU.so, not found (try using -rpath or -rpath-link)
ld: warning: libintlc.so.5, needed by ifortcOP1IU.so, not found (try using -rpath or -rpath-link)
即链接工具ld没有找到上面的几个动态库。
解决方法为:
使用LD_LIBRARY_PATH环境变量指定上述动态库的路径
export LD_LIBRARY_PATH=/opt/intel/Compiler/11.1/056/lib/ia32/
编译时指定以上路径
ifort 123.so ex0842m.f90 -L$LD_LIBRARY_PATH
编译通过,但执行时会有错误如下
./a.out: error while loading shared libraries: 123.so: cannot open shared object file: No such file or directory
即编译器没有找到123.so
解决方法为
export LD_LIBRARY_PATH=/opt/intel/Compiler/11.1/056/lib/ia32/:/home/fengwei.igg/ff
其中/home/fengwei.igg/ff应为123.so所在的路径,方便链接器找到123.so
重新编译:
ifort 123.so ex0842m.f90 -L$LD_LIBRARY_PATH
问题解决!生成默认的可执行文件a.out
(3)执行./a.out,正确结果为
This is subroutine
(4)简单过程如下图所示
--fengwei 09.10.3
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-24 08:56
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社