我有这个Fortran代码。
subroutine DLL_TEST_PROJECT_001(dielconst, tandelta, kappa)
! Expose subroutine DLL_TEST_PROJECT_001 to users of this DLL
!
!DEC$ ATTRIBUTES DLLEXPORT::DLL_TEST_PROJECT_001
! Variables
implicit none
real*8::dielconst
real*8::tandelta
complex*16::kappa
! Body of DLL_TEST_PROJECT_001
kappa = dielconst * dcmplx(1.d0, tandelta)
end subroutine DLL_TEST_PROJECT_001
返回值是一个复杂的(C ++中的复杂)。
这是C ++代码。
typedef complex<double> (*forTest)(double, double);
library.load("C:\\forTest");
// The library loads ok.
forTest ft = (forTest)library.resolve("DLL_TEST_PROJECT_001");
// The function resolves ok and we have an address in ft.
// Now if I call the function...
complex<double> d = ft(1.0, 1.0);
// or just...
ft(1.0, 1.0);
// The app crashes with a segmentation fault.
我猜测崩溃与Fortran函数的返回值有关。
任何帮助?
答案 0 :(得分:3)
Fortran子程序
subroutine DLL_TEST_PROJECT_001(dielconst, tandelta, kappa)
real*8 :: dielconst
real*8 :: tandelta
complex*16 :: kappa
等同于C ++ void函数
void c_name(double *dielconst, double *tandelta, complex <double> *kappa)
(提供double
相当于real*8
,这很常见)
原始代码中使用的错误签名导致不匹配和运行时错误。