Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

C++ exceptions broken when linking with ifort (Mac OSX)

$
0
0

I am having troubles using c++ exceptions in a mixed fortran / c++ program. I have written a minimal program that illustrates the problem. The program consist of one fortran file and one c++ file. The fortran code call a function in the c++ file. This c++ function throws and catches an exception.

We have a number of mac computers and when compiling on some computers the program works while on others (most) it doesn't. The exception does not get caught and instead the program terminates with:

libc++abi.dylib: terminating with uncaught exception of type MyExc
forrtl: error (76): Abort trap signal
Image              PC                Routine            Line        Source
libsystem_kernel.  00007FFF8B00A867  Unknown               Unknown  Unknown

Here is the c++ code:

#include <stdio.h>

class MyExc {};

extern "C" void catch_exc_() {
  printf("catch exc\n");

  try {
    throw MyExc();
  }
  catch( ... ) {
    printf("got it\n");
  }

}

Here is the fortran code:

program test_fortran
print *, "run fortran test"
call catch_exc
end

Here is the build command lines:

ifort -fexceptions -c test_fortran.f90
clang -fexceptions -c catch_exc.cpp -o catch_exc.o
ifort catch_exc.o test_fortran.o -lc++ -fexceptions -o test_fortran

To me this seems like a compiler/tool chain problem. But maybe I am doing something wrong. Any ideas?

Thanks


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>