Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shared library - called from C

2 views
Skip to first unread message

Lars Gregersen

unread,
Nov 30, 2000, 3:00:00 AM11/30/00
to
Hi

I'm trying to make a shared library from Fortran code, which I will
call from a C programme. I have a working solution on Windows, but
fail to get functions to return values on Solaris. I'm using the Gnu
compilers on both platforms.

My Fortran definition of a function looks like this:
---
function dllf2 ()
real dllf2
write (*,*) 'in dllf2.'
dllf2 = 3.141
write (*,*) 'dllf2: ', dllf2
return
end
---

...and the C file looks like this (with error checking removed)
---
void *hdll;
float (*procptrf)();

float x;

hdll = dlopen("libf77dll.so",RTLD_NOW);
procptrf = dlsym(hdll, "dllf2_");
x = procptrf();
printf("x=%g\n", x);
---

This piece of code prints:
in dllf2.
dllf2: 3.14100003
x=2.14262

I guess my problems has something to do with the difference in calling
convention between C and Fortran. What can I do about it? Any clues?

Lars

M.Sc. Chem. Engng. Lars Gregersen
Dep. Chem. Engineering, DTU, Denmark
l...@kt.dtu.dk

0 new messages