- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Yes, this works just fine with icc & ifort 15.0 on OSX 10.9.5
$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.0.077 Build 20141101
Copyright (C) 1985-2014 Intel Corporation. All rights reserved.
$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.0.071 Build 20140709
Copyright (C) 1985-2014 Intel Corporation. All rights reserved.
$ ifort -fexceptions -c test_fortran.f90
$ icc -fexceptions -c catch_exc.cpp
$ ifort catch_exc.o test_fortran.o -lc++ -o test_fortran
$ ./test_fortran
run fortran test
catch exc
got it
$
Patrick
コピーされたリンク
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
See this discussion: https://software.intel.com/en-us/forums/topic/506739
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Please note that I am not trying to use exceptions in fortran code. The exception is thrown and caught (or should be caught) in c++ code.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
I don't think you did anything wrong. It just doesn't work with the exception handling table generated by the Mac clang compiler.
Just as a sanity/logic check, your examples work fine with icc/ifort on Linux:
[U535143]$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.1.133 Build 20141023
Copyright (C) 1985-2014 Intel Corporation. All rights reserved.
[U535143]$ icc -fexceptions -c catch_exc.cpp
[U535143]$ ifort -fexceptions -c test_fortran.f90
[U535143]$ ifort test_fortran.o catch_exc.o -o test_fortran -lstdc++
[U535143]$ ./test_fortran
run fortran test
catch exc
got it
[U535143]$
Patrick
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Would it work on mac if I used icc instead of clang?
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
I think it should work with icc on MAC, if not, I'd consider it a bug. Unfortunately I don't have a MAC system to test on, but I'll ask a colleague who does to check it out.
Patrick
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Yes, this works just fine with icc & ifort 15.0 on OSX 10.9.5
$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.0.077 Build 20141101
Copyright (C) 1985-2014 Intel Corporation. All rights reserved.
$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.0.071 Build 20140709
Copyright (C) 1985-2014 Intel Corporation. All rights reserved.
$ ifort -fexceptions -c test_fortran.f90
$ icc -fexceptions -c catch_exc.cpp
$ ifort catch_exc.o test_fortran.o -lc++ -o test_fortran
$ ./test_fortran
run fortran test
catch exc
got it
$
Patrick
