Macos 在OS X 10.8上使用gfortran对函数指针进行非法文本重定位
我在通过自制安装了Xcode 5.0.2和gfortran 4.8.2的OS X 10.8系统上收到以下错误消息Macos 在OS X 10.8上使用gfortran对函数指针进行非法文本重定位,macos,fortran,shared-libraries,gfortran,fortran-iso-c-binding,Macos,Fortran,Shared Libraries,Gfortran,Fortran Iso C Binding,我在通过自制安装了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/_r4gjs1d363176f99wgkpwl
% 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
如果您能帮助解决此错误,我们将不胜感激。我认为compute()函数编写得不好,请尝试以下方法:
function compute() bind(c) result(out)
use, intrinsic :: iso_c_binding
implicit none
integer(c_int) :: out
out = 1
return
end function compute
没有变化。这会产生同样的结果。对于“写得不好”的问题,你有什么不同的建议?我同意问题中给出的代码不符合Fortran,但您做了不止一个更改。这个问题已在gcc Fortran bugzilla网站上讨论过。您可以在此处查看详细信息: