linux ifort编译命令,科学网—linux下利用ifort编译DLL - 冯伟的博文

以彭国伦的《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)简单过程如下图所示

e40a1d1ab1d0475744c4362478bc0419.png

a283d396e1b507c6c53c54f20076a116.png

--fengwei 09.10.3

转载本文请联系原作者获取授权,同时请注明本文来自冯伟科学网博客。

链接地址:http://blog.sciencenet.cn/blog-271986-277035.html

上一篇:Linux下对NetCDF文件的简单使用方法

下一篇:Linux环境下Lapack软件包的编译和使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值