ctypes 및 공유 라이브러리를 사용하는 동안 NaN 트랩에 약간의 문제가 있습니다. 그런 다음이로드공유 라이브러리의 NaN 트랩 설정
gfortran -o nantest.os -c -g -fbacktrace -ffpe-trap=invalid,zero,overflow -fPIC nantest.f90
gfortran -o libnantest.so -shared nantest.os
:
nantest.f90
subroutine nantest
real :: a, b, c
a = 0.
b = 0.
c = a/b
print *, c,a,b
end subroutine nantest
program main
call nantest
end program main
내가 옵션을 사용하여 그것에서 공유 라이브러리를 만든 : 라이브러리는 포트란으로 작성하고 '0으로 나누기'라인을 가지고있는 서브 루틴으로 구성되었다 파이썬 스크립트 라이브러리 권리 :
from ctypes import *
lib = CDLL('./libnantest.so')
lib.nantest_()
그것은 나에게 예외없이 출력을 제공합니다
을3210 NaN 0.00000000 0.00000000
무엇이 잘못 되었나요? 그것은 ctypes 또는 컴파일러 옵션 문제입니까? BTW, 난 내가 원하는 걸 얻었 같은 컴파일러 옵션으로 내장 'nantest'프로그램을 직접 실행을 수행 할 때 :
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#0 0x7F4D08B6FE08
#1 0x7F4D08B6EF90
#2 0x7F4D087C04AF
#3 0x40080D in nantest_ at nantest.f90:7
#4 0x4008B9 in MAIN__ at nantest.f90:14
Floating point exception
그래서, 어떻게 공유 라이브러리의 경우에 할머니 예외를받을 수 있나요? 추천 사항이 있으십니까?