0

So I have installed openblas and LAPACK on my Mac using Homebrew. I have found the cblas.h file in the path

/usr/local/Cellar/openblas/0.3.20/include

I would like to test it with a simple C++ program, elloBLAS.cpp


    #include <stdio.h>
    #include <cblas.h>
     
    int
    main ()
    {
      int i;
      double x[] = { 1, 1, 1 };
     
     
      cblas_dscal(3, 4.323, x, 1);
     
      for (i = 0; i < 3; ++i)
        printf ("%f\n", x[i]);
     
      return 0;
    }

Using g++ I run in the terminal


    g++ -I /usr/local/Cellar/openblas/0.3.20/include elloBLAS.cpp  
    -o    BLAS_example

I get the compiler error


    e elloBLAS.cpp  -o BLAS_example
    Undefined symbols for architecture x86_64:
      "_cblas_dscal", referenced from:
          _main in elloBLAS-abf5e3.o
    ld: symbol(s) not found for architecture x86_64

Upon some searching I figured out I need to pass the path to the library as well (actually both the folder where the library is, and the library libblas.dylib itself, all the combos). I tried using both the -L and -I compiler flags (I understand the latter is for header files only, but I am not that deep into the topic so I tried...), for example,


    g++ -I /usr/local/Cellar/openblas/0.3.20/include  -I   
    /usr/local/Cellar/openblas/0.3.20/lib/libblas.dylib elloBLAS.cpp  -o 
    BLAS_example


    g++ -I /usr/local/Cellar/openblas/0.3.20/include  
   -L  /usr/local/Cellar/openblas/0.3.20/lib elloBLAS.cpp  
    -  o BLAS_example

but no success.

Could anyone help me out? Thanks

user37292
  • 215
  • 1
  • 8
  • Note that (1) `l` and `I` are two different letters, one is the lowercase ell and the other is the capital ee (2) the `-l` flag doesn't work this way (3) the library needs to be *after* the .cpp file. TL;DR try `elloBLAS.cpp -lblas`. If the compiler says it cannot find libblas, add `-L /path/to/directory`. – n. 1.8e9-where's-my-share m. Mar 12 '22 at 10:20

0 Answers0