Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Reference for C# (csharp) interface to Fortran

longden_loo
Beginner
938 Views
Ihave a need to package some existing Fortran routines and make their results accessible to a C# driver. From reading this list, it appears that the Fortran module needs to be built as a DLL (rather than .exe). Does anyone have a suggested reference or link that describes this C# requirement (and maybe others)?
I've found a lot of C# mixed language examples, but I'd like to see more explanations to understand what I couldn't (or shouldn't) try in terms of calling Fortran from C#.
Thanks,
Longden
0 Kudos
5 Replies
Steven_L_Intel1
Employee
938 Views
You want to look at the C# documentation for calling "unmanaged code", which indeed has to be built as a DLL.

I have attached a sample program here. It is based on something a user sent me with modifications to get it to work, but I did not "clean it up". It may be helpful nonetheless.
0 Kudos
info3
Beginner
938 Views
Steve,

Thanks for posting this example. I downloaded and opened the Solution OK (by double clicking the visualfortranDll1.sln file), then Build Solution (worked OK), then Right Click>Run to Cursor to "Static void Main" statement (worked OK), then steppped through till I reached the call to "visualfortranDll1(r1, out num, nnn, arrYY, aL, outstring, len, 12);" at which point a message box appeared as follows:

ConsoleApplication4.exe - Unable To Locate Component
This application has failed because libifcoremdd.dll was not found. Re-installing the application may fix this problem.

Note that I didn't make any modifications to any of the downloaded files, I ran them just as they stand.

I posted another message yesterday where I explained how I got this same problem trying to access another program where I tried to re-construct an example downloaded from Intel Support for calling C++ from Fortran (didn't make it into the debugger with that case, although it did compile OK). In fact, I got into other difficulties trying to re-install the IVF 9.0 compiler as explained in my other message. At this point I am not sure whether the libifcoremdd.dll error is in fact a problem with the fortran or perhaps with my .NET set up, what do you think? It does seem a bit strange that this particular problem only occurred after downloading the example programs from this site. Could any of these programs have overwritten my libifcoremmdd.dll or other compiler (either IVF or C++/C#.NET) or perhaps even XP system files? Or could there be some other reason, such as version incompatibility? I am running C++, C# and VB.NET standard editions with IVF 9.0 standard and XP Professional.

I'd really appreciate your help with this. Thanks, Paul C.
0 Kudos
Steven_L_Intel1
Employee
938 Views
In order to run programs built against the DLL libraries, the PATH environment variable has to include the path to Program FilesIntelFortran9.0in
0 Kudos
info3
Beginner
938 Views
Steve,

Thank you for this advice. I have in fact managed to get this working now, both for the downloaded example and for a re-construction of it that I made from scratch. The only problem I have now is that in both cases the console screen re-appears momentarily on each line (also the ones not printing out information) in the Fortran part, thereby slowing it down considerably. How can I get around this?

I am using Debug Multithreaded and not Debug Multithread DLL, which was gaving me the libifcoremd problem. I tried your suggestion to include a reference to the PATH environment variable (in Tools>Options>IntelFortran>General>Libraries, as far as I can tell is the right way to do it from the manual), then changed to Debug Multithread DLL, but this threw up the libifcoremd error message again when trying to enter the Fortran routine. If I keep the PATH environment specification you suggested and then go back to Debug Multithreaded without the DLL specification, this works the same as before, and with the same console screen re-appearance problem as before as well, i.e. including the PATH environment specification appears to have no effect. I can proceed from this point probably OK with just Multithread Debug without specifying the DLL mode, but would ideally like to stop the console screen re-appearance problem. Any suggestions? Thanks.

Regards, Paul C.
0 Kudos
Steven_L_Intel1
Employee
938 Views
You misread my suggestion regarding PATH. I didn't say anything about the Tools..Options in Visual Studio - I meant the system environment variable. This needs to include the folder containing the Intel Fortran run-time DLLs in order to run applications and DLLs linked against the DLL form of the run-time library.

As far as a console window coming up - if you are building the Fortran code as a DLL, that should not occur. If you built as a console application, it would. If you have packaged your Fortran code as an EXE and not a DLL, you'd probably want to do it as a "Fortran Windows Application" so that no window was created. This has the structure of a WinMain routine which contains the code to be executed.
0 Kudos
Reply