从Qt C++调用Fortran函数
Calling a Fortran function from Qt C++
我有这段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函数的返回值有关。
有什么帮助吗?
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
,这是常见的)
原始代码中使用的错误签名导致不匹配和运行时错误。
相关文章:
- 如何使用 std::vector 作为参数调用 Fortran 77 C++函数?
- 如何在 C++14 中编写用于调用 Fortran 函数的通用包装器(按引用调用 --按值调用>)
- 从动态库中加载FORTRAN函数:Debug vs Release
- 将 Fortran 函数链接到 C++
- Cuda/Fortran-对Cuda函数的未定义引用
- 为什么值放置在 fortran 函数的数组中,而在调用 c++ 函数中不存在
- 将C++函数指针传递到Fortran子例程
- 调用 Fortran 函数会使程序挂起
- 从Qt C++调用Fortran函数
- C++中对 Fortran 函数的未定义引用
- Cmake配置文件,用于从FORTRAN代码调用的C++函数中调用C++代码
- 在Fortran中更新两个数组,就像在这个C++函数中一样
- 将unique_ptr传递给库函数(FORTRAN函数)
- Fortran程序调用c++函数时发生编译错误
- 在Visual Studio 2010中使用Fortran调用c++函数
- 如何在C语言中以函数作为参数调用Fortran dll
- 从FORTRAN代码调用的c++函数调用c++函数
- Fortran调用c++指针函数
- 将数组从fortran传递给c++函数
- 使用c++ /intel c++编译器调用fortran函数