Bird分享 http://blog.sciencenet.cn/u/fengweiigg

博文

linux下利用ifort编译DLL

已有 16049 次阅读 2009-12-8 16:12 |个人分类:生活点滴|系统分类:科研笔记

以彭国伦的《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



https://blog.sciencenet.cn/blog-271986-277035.html

上一篇:Linux下对NetCDF文件的简单使用方法
下一篇:Linux环境下Lapack软件包的编译和使用
收藏 IP: .*| 热度|

0

发表评论 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-26 00:01

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部