我有一个fortran库,当从一个visual c ++项目中调用时会崩溃。我希望就如何解决这个问题提出建议。
fortran库是Arpack(http://www.caam.rice.edu/software/ARPACK/),我使用gfortran目标x64进行了编译。然后我使用Mingw创建了.dll和.lib文件。
我使用visual c ++(visual studio 2013)从x64项目调用fortran库。代码正确编译,当我逐步调试调试器时,我可以看到函数dsaupd被成功调用多次,其变量在每次调用后都会更新。在第5次调用dsaupd时,程序崩溃,退出代码为0。
调用Fortran方法的c ++函数是:
void arpack_shiftinvert::solve()
{
int IDO = 0;
INFO = 0;
bool continueLoop = true;
while(continueLoop){
//call arpack function for shift-inverted lanczos algorithm
dsaupd_(&IDO, &BMAT, &N, WHICH, &NEV, &TOL, RESID, &NCV, V, &LDV, IPARAM, IPNTR, WORKD, WORKL, &LWORKL, &INFO);
switch (IDO)
{
case -1:
std::cout << "IDO = " << IDO << "\n";
for (int i = 0; i < 3 * N; i++){
std::cout << "WORKD[" <<i << "] = " << WORKD[i] <<"\n";
}
for (int i = 0; i < N; i++){
WORKD[i + IPNTR[1]-1] = (1+i)*WORKD[i + IPNTR[0]-1];
}
break;
case 1:
std::cout << "IDO = " << IDO << "\n";
for (int i = 0; i < 3 * N; i++){
std::cout << "WORKD[" << i << "] = " << WORKD[i] << "\n";
}
for (int i = 0; i < N; i++){
WORKD[i + IPNTR[1]-1] = (1+i)*WORKD[i + IPNTR[2]-1];
}
break;
case 2:
std::cout << "IDO = " << IDO << "\n";
for (int i = 0; i < 3 * N; i++){
std::cout << "WORKD[" << i << "] = " << WORKD[i] << "\n";
}
memcpy(&WORKD[IPNTR[1] - 1], &WORKD[IPNTR[0] - 1], N * 8);
default:
continueLoop = false;
}
}
dseupd_(&RVEC, &HOWMNY, SELECT, D, Z, &LDZ, &SIGMA, &BMAT, &N, WHICH, &NEV, &TOL, RESID, &NCV, V, &LDV, IPARAM, IPNTR, WORKD, WORKL, &LWORKL, &INFO);
std::cout << "Eigenvalues:\n";
for (int i = 0; i < NEV; i++){
std::cout << D[i] << "\n";
}
}
c ++标题是:
extern "C" {
void __stdcall dsaupd_(int *IDO, char *BMAT, int *N, char *WHICH, int *NEV, double *TOL, double* RESID, int *NCV, double *V, int* LDV, int *IPARAM, int *IPNTR, double *WORKD, double *WORKL, int *LWORKL, int *INFO);
void __cdecl dseupd_(bool *RVEC, char *HOWMNY, bool *SELECT, double *D, double *Z, int *LDZ, double *SIGMA, char *BMAT, int *N, char *WHICH, int *NEV, double *TOL, double* RESID, int *NCV, double *V, int* LDV, int *IPARAM, int *IPNTR, double *WORKD, double *WORKL, int *LWORKL, int *INFO);
}
class arpack_shiftinvert
{
public:
arpack_shiftinvert();
~arpack_shiftinvert();
void solve();
}
崩溃时的输出是:
&#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Private \ F2C \ x64 \ Debug \ F2C.exe&#39;。符号已加载。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ ntdll.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ kernel32.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ KernelBase.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Private \ F2C \ x64 \ Debug \ arpack_x64.dll&#39;。模块没有符号。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Private \ F2C \ x64 \ Debug \ libgfortran-3.dll&#39;。模块没有符号。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Private \ F2C \ x64 \ Debug \ libquadmath-0.dll&#39;。模块没有符号。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Private \ F2C \ x64 \ Debug \ libgcc_s_seh-1.dll&#39;。模块没有符号。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ msvcrt.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Private \ F2C \ x64 \ Debug \ libwinpthread-1.dll&#39;。模块没有符号。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ advapi32.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ sechost.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ rpcrt4.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ user32.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ gdi32.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ lpk.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ usp10.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ msvcp120d.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ msvcr120d.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ apphelp.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ imm32.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ msctf.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ PROGRA~2 \ Sophos \ SOPHOS~1 \ SOPHOS~2.DLL&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已加载&#39; C:\ Windows \ System32 \ psapi.dll&#39;。无法找到或打开PDB文件。 &#39; F2C.exe&#39; (Win32):已卸载&#39; C:\ Windows \ System32 \ apphelp.dll&#39; 该程序&#39; [23368] F2C.exe&#39;已退出代码0(0x0)。