linker - Fortran 语言绑定错误:为什么不链接到 MPI 库?
问题描述
我正在尝试为消息传递接口创建语言绑定,但编译器无法识别我对 C 函数的引用...
我目前在 linux 机器上使用 gfortran 作为我的编译器...我知道语言绑定有效,但是每当我尝试将它们链接到 mpi 库时,我都会收到此错误:
/tmp/ccwukrNT.o: In function `MAIN__':
hello_init.f90:(.text+0x17): undefined reference to `mpi_init'
collect2: error: ld returned 1 exit status
我目前使用的编译命令是:
gfortran -ffree-form foo.f90 ~/dir1/dir2/bar.f90 -o <outfile> -L
/home/.fakeroot/lib -I /home/.fakeroot/include/ -lexampi
(exampi 是我目前正在研究的标准)
正如我所说,当我使用简单的 hello_world 程序并手动编译所有文件时,此方法有效,但当我尝试将其链接到库时它会失败。谁能帮我?
这是我当前对 MPI_Init 的 Fortran 绑定:
module mpi_f08
interface MPI_Init
subroutine MPI_Init(ierror) bind(C)
integer, optional, intent(out) :: ierror
end subroutine MPI_Init
end interface MPI_Init
end module mpi_f08
我使用的 C 函数是微不足道的......它只是与 PMPI_Init() 接口......无论如何,库链接是主要问题......是的,我已经从 C++ 外部化了它。
这是我编写的简单测试程序:
program hello_init
use mpi_f08, only : MPI_Init
implicit none
integer :: ierror
ierror = 0
call MPI_Init(ierror)
stop
end program hello_init
我对 Fortran 不太熟悉......这是作为一个副项目给我的,但它很快就占据了我整个星期的时间,同时又笑又哭
谢谢!
解决方案
推荐阅读
- python - 为什么以下代码在 C 和 Python 中给出不同的输出?
- reactjs - recharts中饼图提供cornerRadius后如何加入
- r - 为什么在ggplot的geom_bar中需要stat =“identity”?
- kubernetes - Kubernetes 服务外部名称
- python - Python 滚动浏览您的 Instagram 关注者列表上的溢出滚动框?
- prolog - 如何在 Prolog 中从家谱中找到所有双胞胎
- vue.js - Vue:是否可以在 Vuex 动作中设置另一个状态?
- java - 将 HFM(Hyperion 财务管理)VB 迁移到 Java 新 API
- encryption - 如何使用 node forge 解密 CMS /PKCS#7
- mysql - API MEN(Mysql、expressjs 和 nodejs)