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

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

Morway__Eric
Beginner
638 Views

 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.  

0 Kudos
9 Replies
Steven_L_Intel1
Employee
638 Views

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.

0 Kudos
Morway__Eric
Beginner
638 Views

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

0 Kudos
mecej4
Honored Contributor III
638 Views

 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.

0 Kudos
Morway__Eric
Beginner
638 Views

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?

0 Kudos
mecej4
Honored Contributor III
638 Views

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

[bash] Fortran main running...
 Hello from C#
 C++ call returns          55
 Fortran main finishing...[/bash]

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

0 Kudos
SergeyKostrov
Valued Contributor II
638 Views
Did you try to declare Cxx function as: ... DllExport int __cdecl Cxx( int i, int j ) ...
0 Kudos
mecej4
Honored Contributor III
638 Views

Sergey Kostrov wrote:

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.

0 Kudos
SergeyKostrov
Valued Contributor II
638 Views
>>>>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.
0 Kudos
Morway__Eric
Beginner
638 Views

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

0 Kudos
Reply