Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

How to let the program output runtime error information in C++ code?

Zhanghong_T_
Novice
432 Views

Dear all,

I have the C++ dynamic linked library built by VS2012+Intel C++ 14.0, the dynamic linked library is called by Fortran main program.

Currently there are some problems in the C++ code and I need to locate it. However, the bug can't be reproduced in Debug mode but in Release mode, I can't get to know where the crash happened. I have set /Zi option in 'C/C++' and /DEBUG option in 'Linker', but the output message is as follows:

forrtl: severe (157): Program Exception - access violation
Image              PC                Routine            Line        Source

CSGlib.dll         000007FEEF57DF1E  Unknown               Unknown  Unknown
CSGlib.dll         000007FEEF57DB5F  Unknown               Unknown  Unknown
CSGlib.dll         000007FEEF57D78D  Unknown               Unknown  Unknown
fem.exe            000000013FD6F26E  ELEMENT_mp_LOCALM       20494  datatype.f90

fem.exe            000000013FDE82ED  ELEMENT_mp_TESTME       20389  datatype.f90

fem.exe            000000013FF1DFEF  LOGGING3D..0             4600  main.f90
fem.exe            000000013FEFE700  MAIN_PARALLEL             240  main.f90
fem.exe            000000013FE8C02D  MAIN__                     39  main.f90
fem.exe            00000001429799B6  Unknown               Unknown  Unknown
fem.exe            0000000140950D88  Unknown               Unknown  Unknown
kernel32.dll       000000007775652D  Unknown               Unknown  Unknown
ntdll.dll          000000007798C541  Unknown               Unknown  Unknown

 

where fem.exe is the Fortran main program and CSGlib.dll is the C++ dynamic linked library. I can get to know the crash location of Fortran code but can't get to know the location of C++ code.

What do I miss in project settings?

 

Thanks,

Zhanghong Tang

0 Kudos
4 Replies
pbkenned1
Employee
432 Views

If you C++ DLL is built with Intel C++, try adding compiler option /traceback,  You have to add this in the 'command line' box in Visual Studio, ie, there is no IDE equivalent for /traceback.

Patrick

0 Kudos
Zhanghong_T_
Novice
432 Views

Dear Patrick,

Thank you very much for your kindly reply. I tried to add the compiler option /traceback and rebuilt the project. The result is still the same.

Are there any other options (include path to output .pdb file, currently I output all .pdb files into the same location as the .exe file) should be set?

Thanks

0 Kudos
Zhanghong_T_
Novice
432 Views

BTW: what's the standard method to build a Fortran main program callable C++ DLL? my steps:

1) create a DLL by VS2012's guide;

2) in C++ source file's header give the definition of the function:

extern "C" void readply(myobj *object, char *filename);

3) in Fortran file define the following interface:

 

  interface

  subroutine readply(object,filename) bind(c,name='readply')
    use iso_c_binding
    implicit none
    type(c_ptr),value::object,filename
    end subroutine

...

4) in Fortran project->Linker->Input->Additional Dependencies: add CSGlib.lib, where the CSGlib is the C++ DLL.

By this method, the following warning message displayed:

2>ipo_12568obj32.obj : warning LNK4197: export 'readply' specified multiple times; using first specification

 

Is this message the reason that runtime error can't be located in C++ code? How to remove this warning message?

Thanks

 

0 Kudos
pbkenned1
Employee
432 Views

Issue continued on the IVF forum here.

Patrick

0 Kudos
Reply