Fortran/C++/C# solution compiles, runs, crashes!

Fortran/C++/C# solution compiles, runs, crashes!

 I've gotten to a point with some example Fortran/C++/C# code where I can build the solution, but when I try to execute the code, it crashes with the error message at the top of the attached document ("Microsoft Visual C++ Debug Library Debug Assertion Failed...").  The attached file also shows a screen shot of the Vis. Studio solution and the resulting 'breakpoint' when I click "Retry" on the preceding window.  I'm wondering if I'm missing a C++ header file to go with the C++ source code (Cxx.cc)?  Unfortunately, I don't know C++ very well.

The code crashes when it gets to the following line of Fortran shown in the middle tab group of the screen shot:

PRINT *, "C++ call returns", Cxx( i, j )

If any one can tell from the solution set up shown in the screen shot what could be at the root of this error, that would be very helpful.  I think the code was working outside of visual studio when it was shared with me, but I'm trying to get working from inside visual studio.  

AttachmentSize
Download screenshots.docx239.38 KB
10 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I don't think anyone here can help you based on a screenshot.However, you should also look to see if there is a console window with an additional error message. I have seen this "assertion" error when a Fortran error such as array bounds or uninitialized variable was reported.

Steve - Intel Developer Support

Hello Steve, I wan't able to use the "reply" button, but hopefully this message will find its way to you.  I have attached a screen shot of the console window with the hope that it presents additional information that might lead to pointed suggestions.  Everything (Fortran/C++/C#) compiles OK, links OK, and even runs through several lines of the Fortran Main program before crashing when calling the C++ function.  How can I know if I have array bound or uninitialezed variable problems as you suggested in your post?  Perhaps the screen shots in my first post that show the Fortran and C++ code are helpful?  -Eric

Attachments: 

AttachmentSize
Download console-window-screenshot.docx70.54 KB

Citazione:

 Everything (Fortran/C++/C#) compiles OK, links OK, and even runs through several lines of the Fortran Main program before crashing when calling the C++ function.

That is what every program with a run-time bug does. If such bugs could be fixed on the basis of just that information, such bugs would have been eradicated for ever.

Nor is it helpful that your screenshot tells us only that the crash occurred on Line-nnn without showing the code itself. Using the byte-greedy .docx file format can be a problem for some of us -- a single line of text consuming less than 0.1 kB would have sufficed.

The 3 pieces of the puzzle (Fortran, C++, and C# source code) are attached.  The crash occurs on line 14 of the Fortran code ["PRINT *, "C++ call returns", Cxx( i, j )"].  Hopefully this helps rounds out my previous post, the question remains the same, is it possible to know from looking at the code if I have inadvertant array bound or uninitialezed variable problems?

Attachments: 

AttachmentSize
Download cpp-interface.cpp326 bytes
Download csharp.txt347 bytes
Download fortran-main.f90454 bytes

I fixed up the name discrepancy in the Fortran file by changing "CPP_Interface" to "CPP-Interface", commented out the inclusion of stdafx.h, and built the DLL and EXE in a command window (using the commands included in your source files as comments). The resulting program ran and gave the expected output

 Fortran main running...
 Hello from C#
 C++ call returns          55
 Fortran main finishing...

You need to give more details of how you did the building, including the three sets of compiler options (for Fortran, C++, C#).

Did you try to declare Cxx function as:
...
DllExport int __cdecl Cxx( int i, int j )
...

Citazione:

Sergey Kostrov ha scritto:

Did you try to declare Cxx function as:
...
DllExport int __cdecl Cxx( int i, int j )
...

Sergey, that would not work since the default in Intel Fortran is not to pass arguments by value.

>>>>Did you try to declare Cxx function as:
>>>>...
>>>>DllExport int __cdecl Cxx( int i, int j )
>>>>...
>>
>>Sergey, that would not work since the default in Intel Fortran is not to pass arguments by value.

Thank you for the note.

The code attached to a previous post is of course a small example problem that is a precursor to a larger problem.  The reason for compiling and running from within Visual Studio is so that I can also run the larger problem from within the Visual Studio GUI, where the debugging capabilities are both familiar and helpful.  I've attached the Vis. Studio solution in a zip file with the hope that someone more familiar with the required project settings can help work out the kinks.  Perhaps I should be ashamed that I don't know the equivalent visual studio settings for the following command line settings?

C#: Build CS.dll: csc /target:library CS.cs

C++: Build Cxx.dll: cl /CLR /LD Cxx.cc

Attachments: 

AttachmentSize
Download fortran-cs.zip1.42 MB

Leave a Comment

Please sign in to add a comment. Not a member? Join today