OpenBLAS icon indicating copy to clipboard operation
OpenBLAS copied to clipboard

undefined reference to `cblas_dgemm'

Open johnny2231 opened this issue 3 years ago • 4 comments

Hi, I am trying to run matrix operations in C, I am coding on VScode, when I compile, it gives this message:

>> gcc testtest.c -I "C:\\Users\\experiments\\OpenBlasInstall\\include"

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\ccsrFgiV.o:testtest.c:(.text+0x29a): undefined reference to `cblas_dgemm'
collect2.exe: error: ld returned 1 exit status

I saw an issue describing the same scenario but that is cmake issue.

I am not sure if is it related to the way I install openblas. What I did to install openblas:

  1. download WSL(ubuntu) on window.
  2. on WSL git clone openblas, cd openblas
  3. make BINARY=64 HOSTCC=gcc CC=x86_64-w64-mingw32-gcc FC=x86_64-w64-mingw32-gfortran CFLAGS='-static-libgcc -static-libstdc++ -static -ggdb' FFLAGS='-static' && mv -f libopenblas.dll.a libopenblas.lib
  4. make PREFIX=/mnt/c/Users/experiments/OpenBlasInstall install

May I know how to solve this? Thanks!

johnny2231 avatar Sep 28 '22 23:09 johnny2231

You need to tell gcc that it has to link your code against OpenBLAS, something like gcc testtest.c -I "C:\\Users\\experiments\\OpenBlasInstall\\include" -L "C:\\Users\\experiments\\OpenBlasInstall\\lib" -lopenblas

martin-frbg avatar Sep 29 '22 05:09 martin-frbg

Hi @martin-frbg thanks for the reply, I tried that command but I will get this message:

ld.exe: cannot find -lopenblas: No such file or directory
collect2.exe: error: ld returned 1 exit status

I will need to find out how Windows/VScode can recognize -lopenblas

On Ubuntu, it able to recognize -lopenblas and able to compile successfully, but it will hit error when running the executable:

./a.out: error while loading shared libraries: libopenblas.so.0: cannot open shared object file: No such file or directory

To solve this need to run the cmd below:

export LD_LIBRARY_PATH=/home/OpenBlasBuild/lib

johnny2231 avatar Sep 30 '22 10:09 johnny2231

I tried to reinstall OpenBlas with MSYS2 mingw64, the cmd able to run without error: gcc testtest.c -I "C:\\Users\\experiments\\OpenBlasInstall\\include" -L "C:\\Users\\experiments\\OpenBlasInstall\\lib" -lopenblas

But when I run ./a.exe, there is nothing printed on VScode. The C program is expected to print something. When I run ./a.exe on MSYS2, I see this error: C:/Users/a.exe: error while loading shared libraries: libopenblas.dll: cannot open shared object file: No such file or directory.

And I found this looks the same as this issue: https://github.com/xianyi/OpenBLAS/issues/1321 But that issue is not solved. That issue was created in year 2017, is there anyone have the same issue since then and able to solve it?

I tried export LD_LIBRARY_PATH=/c/Users/experiments/OpenBlasInstall/lib on MSYS2, but it is not working, seems like this command only work on UNIX

johnny2231 avatar Oct 01 '22 03:10 johnny2231

Does it find the dll when you put it in the same place as your testtest.exe ? (Could also be that you need to register the dll with Windows using regsvr32.exe, at least when it was built outside the MSVC environment - but I am not really familiar with coding on that platform)

martin-frbg avatar Oct 01 '22 13:10 martin-frbg

Hi @martin-frbg thanks for the reply. Spent sometime to figure it out, but still not working. I think I will do what issue-1321 did, which is copying functions/variables I want into my code. Thanks!

johnny2231 avatar Oct 09 '22 09:10 johnny2231