Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29312 Discussions

FORTRAN dll interfacing with C++ and other FORTRAN dlls

cfann61
Beginner
1,329 Views
I have a fortran dll 'X' which is called both by a C++ dll and other fortran dlls.

The fortran dlls interface with each other easily.

If I try to have the C dll call X, I get the 'unresolved external _X@24' error. I'm trying to call from C:

X(int, double, double, double*)

I can force X to pass values in this format (int, double, and double by VALUE; double* by REFERENCE), but then the other fortran dlls cannot access X, I get the 'unresolved external __imp_X@'

How are all the values passed if I do not manipulate the VALUE/REFERENCE compiler options?

Is there a way I can define the 'X' function in C so that it will call X correctly without manipulating the compiler options in X?

BTW, my work around for this was to create anintermediate fortran dll wich I've set the VALUE/REFERENCE compiler options, then called X from there. I would like to get rid of the intermediate dll.

Thanks

Chris
0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,329 Views
It would appear that your C code has declared X as __stdcall, thus the @24. Intel Fortran, by default, doesn't use STDCALL. If you show us the entire declaration of X in the C code we can suggest how to change it. This has nothing to do with value/reference. However, your declaration of X does have the first two arguments passed by value. If you changed all of the arguments to *int or *double, and passed addresses (&arg) rather than just the arg value, then it would work without changes in the Fortran. There is no way to avoid changing one or the other.
0 Kudos
cfann61
Beginner
1,329 Views
I have used STDCALL do define the function in C like this:

extern "C" void _stdcall STMPROP(int * runoption, double * pressure, double * temperature, double * RET);

I am also passing addresses with &

Is there a way to define it in C to avoid making changes to the fortran dll?
0 Kudos
Steven_L_Intel1
Employee
1,329 Views
Take out the __stdcall for a start.
0 Kudos
cfann61
Beginner
1,329 Views
That did the trick.

Thanks
0 Kudos
cfann61
Beginner
1,329 Views
How would I define a string in the routine?

I was thinking link this:

extern "C" void STMPROP(char * string, int strlen);

Haven't tried this yet, just curious.
0 Kudos
Steven_L_Intel1
Employee
1,329 Views
Rather than int, use size_t. Also, all the string lengths go at the end of the argument list, so if you had two arguments, a string and a real, it would look something like this:

extern "C" void SUB(char * string, float *r, size_t strlen);

This assumes you are not using the C interoperability features of Fortran.
0 Kudos
Reply