clapack package example

Pages: 12
@George P I tried installing the library using vcpkg at the very beginning. The problem is not installing. I have clapack installed on my machine but I think something inside the library is going wrong.
Last edited on
M'ok, if'n that is the case, the library is possibly hosed, you should contact the library's author/maintainer. They know more about what's going on than anyone here, and have ideas to fix the issue(s) if there is one.

Don't forget the problem still might be with your installation.
Last edited on
I haven't tried DUMPBIN, I even don't know what that is.


DUMPBIN provides various information about .exe/.dll/.lib files.

See https://docs.microsoft.com/en-us/cpp/build/reference/dumpbin-reference?view=msvc-170


In this case, the /EXPORTS option is what is of interest.
dumpbin /exports /symbols lapack.lib
produces _dgesv_
i.e. an underscore is prepended to the symbol name.

Apparently this is some sort of calling convention (no, I don't understand it), but it was used by default when compiling for 32-bit (which I suspect, from the date, that those libraries were)

Unfortunately, modern compilers produce an object file with just dgesv_, so they don't match.

Either work out how to match the calling convention of the older libraries when you compile test.c, or use newer libraries compiled for x64.
I got it worked.
I again downloaded the clapack using curl -O https://icl.cs.utk.edu/lapack-for-windows/clapack/clapack-3.2.1-CMAKE.tgz. Then unzipped it using 7zip, built it using cmake. Then I Included the f2c header file in clapack and changed the typedef long int integer; to typedef int integer (thanks to @lastchance) and run the following example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include "clapack.h"
#include "f2c.h"


//extern "C" void dgesv_(const int* N, const int* nrhs, double* A, const int* lda, int
//    * ipiv, double* b, const int* ldb, int* info);
//
//extern "C" void dgels_(const char* trans, const int* M, const int* N, const int* nrhs,
//    double* A, const int* lda, double* b, const int* ldb, double* work,
//    const int* lwork, int* info);

int main(int argc, char* argv[])
{
    /* 3x3 matrix A
     * 76 25 11
     * 27 89 51
     * 18 60 32
     */
    double A[9] = { 76, 27, 18, 25, 89, 60, 11, 51, 32 };
    double b[3] = { 10, 7, 43 };

    int N = 3;
    int nrhs = 1;
    int lda = 3;
    int ipiv[3];
    int ldb = 3;
    int info;

    dgesv_(&N, &nrhs, A, &lda, ipiv, b, &ldb, &info);

    if (info == 0) /* succeed */
        printf("The solution is %lf %lf %lf\n", b[0], b[1], b[2]);
    else
        fprintf(stderr, "dgesv_ fails %d\n", info);

    char my_char;
    my_char = getchar();

    return info;

}



The solution is -0.661082 9.456125 -16.014625
Last edited on
Topic archived. No new replies allowed.
Pages: 12