0

我在通过自制软件安装了 Xcode 5.0.2 和 gfortran 4.8.2 的 OS X 10.8 系统上收到以下错误消息。

% gfortran -shared f03_iso_c.f03
ld: illegal text-relocation to '_compute' in /var/folders/w3/_r4gjs1d363176f99wgkpwl80000gn/T//cc8VFCuI.o from 'anon' in /var/folders/w3/_r4gjs1d363176f99wgkpwl80000gn/T//cc8VFCuI.o for architecture x86_64
collect2: error: ld returned 1 exit status

f03_iso_c.f03 的内容是

module F03_ISO_C
  use, intrinsic :: iso_c_binding

  contains

  integer(c_int) function compute() bind(c) result(compute)
    use, intrinsic :: iso_c_binding
    implicit none

    compute = 1
    return

  end function compute

end module F03_ISO_C

integer function F03_ISO_C_init()
  use F03_ISO_C
  use, intrinsic :: iso_c_binding

  implicit none

  call USE_FUNC_PTR(c_funloc(compute))

  F03_ISO_C_init = 1
  return

end function F03_ISO_C_init

subroutine USE_FUNC_PTR(f1)
  use, intrinsic :: iso_c_binding

  implicit none

  type(c_funptr) :: f1

  print *, f1, "is the address"

end subroutine USE_FUNC_PTR

任何解决此错误的帮助将不胜感激。

4

1 回答 1

0

我会说函数 compute() 写得不好,试试这个:

function compute() bind(c) result(out)
    use, intrinsic :: iso_c_binding
    implicit none
    integer(c_int) :: out

    out = 1
    return

 end function compute
于 2014-01-24T07:38:00.940 回答