Thanks for the reply, Alex_Dubinsky, but…
…the issue (or, at least part of it) is that clapack is an incomplete implementation of the LAPACK library, so the header file doesn’t include a prototype for the function I need. And, just for clarity, the purpose of the “-lg2c” switch isn’t to link specifically to the LAPACK library, but to enable linking to a Fortran library.
So, for those who have any interest in this, I’ve resolved it enough to do what I want, and I believe I understand what the underlying issues was. First, what worked:
I came across this post, which indicates that the problem was indeed declaring the function as extern “C”. After adding such a declaration, the test program compiled without a problem, and executed just fine. I’ve added something similar to my own header file and it compiled; I haven’t tested execution yet, as there are some details I still need to address (e.g., row-major matrices in C vs. column-major in Fortran, actual test data, etc.), but I expect it to work as advertised.
Now, the underlying issue: I’m pretty sure it’s the name-mangling that C++ does (after all, isn’t that the whole reason for the “C” part of extern “C”?), compounded by the fact that there isn’t a proper header file for the LAPACK library. And it was even further exacerbated by the unknown-to-me style found in my first link (embedding an extern within a function). So, the practical outcome is that while this:
...
static long
dgtsv(long N, long NRHS, double *DL, double *D, double *DU, double *B, long LDB) {
extern void dgtsv_(const long *Np, const long *NRHSp, double *DL, double *D, double *DU, double *B, const long *LDBp, long *INFOp);
long info;
dgtsv_(&N, &NRHS, DL, D, DU, B, &LDB, &info);
return info;
}
...
works in C, it doesn’t work in C++. However, the following compiles and executes with both gcc and g++:
...
#ifdef __cplusplus
extern "C" void dgtsv_(const long *Np, const long *NRHSp, double *DL, double *D, double *DU, double *B, const long *LDBp, long *INFOp);
#else
extern void dgtsv_(const long *Np, const long *NRHSp, double *DL, double *D, double *DU, double *B, const long *LDBp, long *INFOp);
#endif
...
static long
dgtsv(long N, long NRHS, double *DL, double *D, double *DU, double *B, long LDB) {
long info;
dgtsv_(&N, &NRHS, DL, D, DU, B, &LDB, &info);
return info;
}
...
Took me a few hours to figure out, but it’s definitely something I’m not likely to soon forget. 