0

I am running following program using command

gcc filename.c -o filename.exe

and it shows error

"AppData/Local/Temp/cc4rF2ac.o:filename.c:(.text+0xd4): undefined reference to LAPACKE_dgels' collect2.exe: error: ld returned 1 exit status"

    /* Calling DGELS using column-major order */

#include <stdio.h>
#include <stdlib.h>
#include <lapacke.h>
#include <math.h>


lapack_int main (int argc, const char * argv[])
{
   double a[5*3] = {1,2,3,4,5,1,3,5,2,4,1,4,2,5,3};
   double b[5*2] = {-10,12,14,16,18,-3,14,12,16,16};
   lapack_int info,m,n,lda,ldb,nrhs;
   int i,j;

   m = 5;
   n = 3;
   nrhs = 2;
   lda = 5;
   ldb = 5;

   info = LAPACKE_dgels(LAPACK_COL_MAJOR,'N',m,n,nrhs,a,lda,b,ldb);

   for(i=0;i<n;i++)
   {
      for(j=0;j<nrhs;j++)
      {
         printf("%lf ",b[i+ldb*j]);
      }
      printf("\n");
   }
   return(info);
}
danielschemmel
  • 10,885
  • 1
  • 36
  • 58
chandan
  • 1
  • 1
  • 2
  • 2
    The signature of main is `int main(int, char**);` or `int main();` – danielschemmel Apr 08 '15 at 11:24
  • If this is C code, why is this question tagged C++? – David Schwartz Apr 08 '15 at 11:25
  • 1
    Compile with `gcc filename.c -o filename.exe -llapacke`. – Wintermute Apr 08 '15 at 11:27
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – moffeltje Apr 08 '15 at 11:29
  • @gha.st a main signature may be `int main(int, const char**);` or `int main(int, const char* []);`. It has no link with this problem. – Aracthor Apr 08 '15 at 11:36
  • @Aracthor You have written the *same prototype twice*. And both are wrong. Nevertheless, it does not cause linker errors in this case, as GCC will discard any type information anyway, and link it only by its name (C does not support overloading after all). This is why my comment was a comment - even under assumption that `lapack_int` is a `typedef` for `int` (and not e.g. `long`), this triggers implementation defined behavior. – danielschemmel Apr 08 '15 at 11:42

1 Answers1

1

You are missing a library. rerun GCC adding -llapacke :

gcc filename.c -o filename.exe -llapacke

Assuming your library is something like liblapacke.a or liblapacke.so. Else, rerun adding -lNAME, with NAME the name of your lib file without the "lib" and the ".a" or ".so".

Aracthor
  • 5,757
  • 6
  • 31
  • 59