Mixed Language Programming
-
In my line of work I have times when I have to included existing code modules in with my new code. So happens this time I have an existing set of subroutines in a Fortran DLL that I need to access from my C++ Code. I can't get it to work following Microsoft's recommendations. Does anyone out there have any ideas the may work? For those of you who thing I should rewrite the Fortran in C++ it would take entirely too long to do that. I figure there are a few thousand lines of Fortran code. Thanks, George :confused:
-
In my line of work I have times when I have to included existing code modules in with my new code. So happens this time I have an existing set of subroutines in a Fortran DLL that I need to access from my C++ Code. I can't get it to work following Microsoft's recommendations. Does anyone out there have any ideas the may work? For those of you who thing I should rewrite the Fortran in C++ it would take entirely too long to do that. I figure there are a few thousand lines of Fortran code. Thanks, George :confused:
BubbaGee wrote: I can't get it to work... Why not? What are the symptoms? Are the functions in the Fortran DLL exported? Are you importing them correctly in the C++ code?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
BubbaGee wrote: I can't get it to work... Why not? What are the symptoms? Are the functions in the Fortran DLL exported? Are you importing them correctly in the C++ code?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
The functions in the Fortran have the following: !DEC$ ATTRIBUTES DLLEXPORT :: INITIA and the C++ code has this: extern "C" {void INITIA(int,int,int,int);} There are a few of these since I'm trying to access eight routines in the DLL. Everything is compiling just fine I just get LNK2019 error messages for all the routines I'm trying to use in the C++ code. George
-
The functions in the Fortran have the following: !DEC$ ATTRIBUTES DLLEXPORT :: INITIA and the C++ code has this: extern "C" {void INITIA(int,int,int,int);} There are a few of these since I'm trying to access eight routines in the DLL. Everything is compiling just fine I just get LNK2019 error messages for all the routines I'm trying to use in the C++ code. George
BubbaGee wrote: I just get LNK2019 error messages... This must not be VS6. Correct? Are you sure you have the correct signature for the exported function?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
The functions in the Fortran have the following: !DEC$ ATTRIBUTES DLLEXPORT :: INITIA and the C++ code has this: extern "C" {void INITIA(int,int,int,int);} There are a few of these since I'm trying to access eight routines in the DLL. Everything is compiling just fine I just get LNK2019 error messages for all the routines I'm trying to use in the C++ code. George
Why not trying a LoadLibrary GetProcAddress sequence. If you are able to get the function pointer, all you need afterward is to define it with the good calling convention. To get the name of the function, try dumpbin or dependency walker Papa while (TRUE) Papa.WillLove ( Bebe ) ;
-
BubbaGee wrote: I just get LNK2019 error messages... This must not be VS6. Correct? Are you sure you have the correct signature for the exported function?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
In my line of work I have times when I have to included existing code modules in with my new code. So happens this time I have an existing set of subroutines in a Fortran DLL that I need to access from my C++ Code. I can't get it to work following Microsoft's recommendations. Does anyone out there have any ideas the may work? For those of you who thing I should rewrite the Fortran in C++ it would take entirely too long to do that. I figure there are a few thousand lines of Fortran code. Thanks, George :confused:
Note, you don't *have* to use a DLL for this to work. You can simply link all the stuff together. You do have to take into account different parameter passing mechanisms (e.g., C++ strings do not map to Fortran strings!) but that is the same as if you use a DLL. I don't remember all the details, though, so I'm useless. But I think if you have a Fortran compiler that links into Visual Studio (they exist), you can do this relatively painlessly. "Fish and guests stink in three days." - Benjamin Franlkin
-
Note, you don't *have* to use a DLL for this to work. You can simply link all the stuff together. You do have to take into account different parameter passing mechanisms (e.g., C++ strings do not map to Fortran strings!) but that is the same as if you use a DLL. I don't remember all the details, though, so I'm useless. But I think if you have a Fortran compiler that links into Visual Studio (they exist), you can do this relatively painlessly. "Fish and guests stink in three days." - Benjamin Franlkin
-
The functions in the Fortran have the following: !DEC$ ATTRIBUTES DLLEXPORT :: INITIA and the C++ code has this: extern "C" {void INITIA(int,int,int,int);} There are a few of these since I'm trying to access eight routines in the DLL. Everything is compiling just fine I just get LNK2019 error messages for all the routines I'm trying to use in the C++ code. George
I don't think you are following Micro$oft's recommendations. I just checked MSDN and it says to use __stdcall for FORTRAN functions. For more info search for mixed-language programming in the MSDN docs. __________________________________________ a two cent stamp short of going postal.