Fortran派生类型构造函数通过C函数定义

我想通过C函数定义派生类型构造函数。 在下面的示例中,我设法通过C接口定义了一个重载的加法运算符。 尽管语法非常相似,但构造函数的定义在gfortran 4.9下失败,并出现以下错误:

test.f90:7.52: module procedure my_module_fortran_new_my_double 1 Error: 'my_module_fortran_new_my_double' at (1) is not a module procedure 

经过一段时间花在谷歌搜索或查看堆栈溢出前的post,我没有找到任何解决方案。 如果有人能告诉我是什么触发了这个错误以及如何纠正它,我会很高兴。

这是我的模块的源代码:

 module my_module use iso_c_binding type, bind(c) :: my_double real(c_double) :: x end type my_double interface my_double module procedure my_module_fortran_new_my_double end interface interface operator (+) module procedure my_module_fortran_add end interface operator (+) interface type(my_double) function my_module_fortran_new_my_double (v) bind ( c ) use iso_c_binding import :: my_double real (c_double), intent(in) :: v end function my_module_fortran_new_my_double type(my_double) function my_module_fortran_add (v1,v2) bind ( c ) use iso_c_binding import :: my_double type (my_double), intent(in) :: v1,v2 end function my_module_fortran_add end interface end module my_module 

外部过程不是模块过程。 我想这就是你想要的:

 module my_module use iso_c_binding type, bind(c) :: my_double real(c_double) :: x end type my_double interface type(my_double) function my_module_fortran_new_my_double (v) bind ( c ) use iso_c_binding import :: my_double real (c_double), intent(in) :: v end function my_module_fortran_new_my_double type(my_double) function my_module_fortran_add (v1,v2) bind ( c ) use iso_c_binding import :: my_double type (my_double), intent(in) :: v1,v2 end function my_module_fortran_add end interface interface my_double procedure my_module_fortran_new_my_double end interface interface operator (+) procedure :: my_module_fortran_add end interface operator (+) end module my_module