10-21-2010 02:58 PM
I'm starting with a simple case in which I have a Fortran subroutine:
SUBROUTINE FSUB (INT_ARG,STR_IN,STR_OUT)
in which the INT_ARG is an integer argument, STR_IN is an input character array (string) and STR_OUT is the output character array (string).
In this case, I think the header file would look
at least that's what I think. Am i right?
10-21-2010 03:28 PM
Well, the order in your subroutine definition doesn't match the order in your .h file. (int, string, string vs. string, int, string).
I also don't know if your Fortran compiler reads the subroutine parameters in the same order as CVI. cdecl pushes the parameters onto the stack right-to-left. I don't know what Fortran does, but if a call crashes, you may want to try reversing the order.
10-22-2010 11:31 AM
Apart from the other solutions suggested so far, you can also try to compile your Fortran code to C and then take it from there. Look at the attached project for an example.
10-23-2010 12:13 AM
The message I found when I tried to debug it was
Undefined symbol '_FSUB' referenced in "fsub2.c"
I tried to call the subroutine FSUB(val,strin,strout) in the source file (I'm not sure if I can call this "subroutine" in a C environment even if I defined the prototype as a C function in the header file) using
FSUB(val, strin, strout);
the HEADER FILE was:
and the FORTRAN SUBROUTINE is:
SUBROUTINE FSUB (INT_ARG, STR_IN, STR_OUT)
INTEGER, INTENT(IN) :: INT_ARG
CHARACTER(*), INTENT(IN) :: STR_IN
CHARACTER(*), INTENT(OUT) :: STR_OUT
CHARACTER(len=5) :: INT_STR
...
I'm sorry guys but even with all the help I'm still having problems trying to use this Fortran subroutine in LabWindows. Is there some kind of tutorial I could use?
#include <cvidef.h> extern void DLLIMPORT FSUB(int dummyint, char * dummycharname1, char * dummycharname2);
10-25-2010 08:08 PM
Hi! Chimbotano,
I can feel the frustration you're encountering now. It is tricky to build DLLs from different programming languages to be accessible for another one. And I'm surprised that the answer from NI's engineer is only "Best of luck!" He/She might as well keep silent.
Anyway, the problem you're facing now is all about syntax. You need to study and understand the Intel Fortran compiler you're using a bit more to export the Fortan functions in correct format and how to write a C header file according the functions exported in the DLL file so that C can use these functions. If you load your DLL files dynamically, all you need is the header file and the DLL file. If the format of the exported functions is incorrect or the header file is not written properly. Nothing works and "Undefined symbol" is the most seen error.
I don't have a solution for you, but here are some links that you might want to study first:
http://zone.ni.com/devzone/cda/tut/p/id/3341#toc8
http://forums.ni.com/t5/LabWindows-CVI/call-DLLs-created-by-VC-in-CVI/td-p/538814
I'm sure you've googled many sites already for solving your problem. Please let us know if you have a better progress.
At the same time, I believe there must be someone in this forum that can give you much better answers or clues than "Best of luck!"
10-26-2010 07:32 AM
I haven't tried any of this myself since I don't know Fortran, but maybe the information at these two links can help you:
http://software.intel.com/en-us/forums/showthread.php?t=72452
For the second link, look under Building Applications >> Using Windows OS Features >> Creating and Using DLLs.
It sounds like you have to declare your Fortran functions like this:
SUBROUTINE FSUB (INT_ARG, STR_IN, STR_OUT)
!DEC$ ATTRIBUTES DLLEXPORT :: FSUB
...
Import them in your C file as:
extern void FSUB(int * INT_ARG, char ** STR_IN, char ** STR_OUT);
And include the Fortran .lib in your CVI project. Use the .lib that was generated by the Fortran compiler. Don't generate your own .lib in CVI from header and DLL. This is just a sanity check to make sure the Fortran compiler actually generates a .lib file. If it doesn't, your Fortran DLL isn't exporting anything and generating an empty .lib in CVI won't help.
I'm not sure about the parameter declarations in the C file. Looking at the first link, it appears that all arguments are passed by reference and that you have to add another pointer * to them. You'll have to experiment, I cannot test this.
Peter