I've looked around, and though there are a lot of EXC_BAD_ACCESS issues, none of them helped.
I'm using Mountain Lion (OSX 10.8 I think?), and PGI 12.
I can't seem to call fortran functions from C, I've written a simplified case and it seems that I can't pass integers.
My fortran function is:
1 integer function smallFortran(a) result(res) bind(c,name='smallFortran_')
2 !integer function smallFortran(a) result(res)
3
4 use ISO_C_BINDING
5 implicit none
6
7 integer(kind=c_int), intent(IN) :: a
8 !integer, intent(IN) :: a
9
10 print *,'A = ', a
11 res = a;
12
13 endfunction smallFortran
And my C function is,
int main() {
int ier=7;
ier = smallFortran_(8);
}
Build it..
matt@pontus:diffFst$ make
pgcc -c cDoDiffFst.c
PGC-W-0267-#warning -- "Unsupported compiler detected" (/usr/include/sys/cdefs.h: 81)
PGC/x86-64 OSX 12.9-0: compilation completed with warnings
pgcc -g -O0 -traceback -o cDoDiffFst cDoDiffFst.o smallFortran.o -lpgf90 -lpghpf2 -lpgf90rtl -lpgftnrtl -lpghpf_rpm
(I hope that warning isn't what's causing my problems, the PGI user forum responds to this by saying they'll send a newer version of the file, but I haven't been replied to yet. And no idea why PGI requires so many extra libraries to be specified)
When I run it in the debugger..
matt@pontus:diffFst$ gdb cDoDiffFst
(gdb) run
Starting program: /Users/matt/aurams/trunk/utils/diffFst/cDoDiffFst
Reading symbols for shared libraries +............................. done
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000008
0x0000000100001906 in _smallFortran_ (a=Cannot access memory at address 0x8
) at smallFortran.f90:10
10 print *,'A = ', a
(gdb)
I'm totally lost, why can't I send an int? I've tried assigning a value to an integer and sending it, no dice. I've tried it as a subroutine, I've tried it without a return value.. nothing works.