Thread overview
Compilation error: undefined reference to 'cblas_dgemv' / 'cblas_dger' / 'cblas_dgemm'
Jan 11, 2020
p.shkadzko
Jan 12, 2020
dnsmt
Jan 13, 2020
p.shkadzko
Mar 10, 2020
Pavel Shkadzko
January 11, 2020
I am trying to run example code from https://tour.dlang.org/tour/en/dub/lubeck

example.d:
---
/+dub.sdl:
dependency "lubeck" version="~>1.1"
+/
import lubeck: mtimes;
import mir.algorithm.iteration: each;
import mir.ndslice;
import std.stdio: writeln;

void main()
{
    auto n = 5;
    // Magic Square
    auto matrix = n.magic.as!double.slice;
    // [1 1 1 1 1]
    auto vec = 1.repeat(n).as!double.slice;
    // Uses CBLAS for multiplication
    matrix.mtimes(vec).writeln;
    "-----".writeln;
    matrix.mtimes(matrix).byDim!0.each!writeln;
}
---

I try to compile it via:

---
dub build --compiler="ldc" --single example.d -v
---

And get the error below:

---
Linking...
ldc -of.dub/build/application-debug-linux.posix-x86_64-ldc_2088-588551E77C1C779CBF3BECA58D19211B/matrix_dot .dub/build/application-debug-linux.posix-x86_64-ldc_2088-588551E77C1C779CBF3BECA58D19211B/matrix_dot.o ../../../../../.dub/packages/lubeck-1.1.7/lubeck/.dub/build/library-debug-linux.posix-x86_64-ldc_2088-09723F6E7A90ABDEB9EDD35B9DC7E7CE/liblubeck.a ../../../../../.dub/packages/mir-lapack-1.2.1/mir-lapack/.dub/build/library-debug-linux.posix-x86_64-ldc_2088-69D3CA650230A9C73F912A6D1AB44EE1/libmir-lapack.a ../../../../../.dub/packages/mir-blas-1.1.9/mir-blas/.dub/build/library-debug-linux.posix-x86_64-ldc_2088-9B27CD5D2C27A78F627CDC352C376E52/libmir-blas.a ../../../../../.dub/packages/mir-algorithm-3.7.13/mir-algorithm/.dub/build/default-debug-linux.posix-x86_64-ldc_2088-255337055B86988DA608A6F2BE06058A/libmir-algorithm.a ../../../../../.dub/packages/mir-core-1.0.2/mir-core/.dub/build/library-debug-linux.posix-x86_64-ldc_2088-554F8271B5559801959D6785138A5389/libmir-core.a -L--no-as-needed -L-lopenblas -g
/home/tastyminerals/dev/github/mir_quickstart/source/benchmarks/../../../../../.dub/packages/mir-blas-1.1.9/mir-blas/source/mir/blas.d:305: error: undefined reference to 'cblas_dgemv'
/home/tastyminerals/dev/github/mir_quickstart/source/benchmarks/../../../../../.dub/packages/mir-blas-1.1.9/mir-blas/source/mir/blas.d:210: error: undefined reference to 'cblas_dger'
/home/tastyminerals/dev/github/mir_quickstart/source/benchmarks/../../../../../.dub/packages/mir-blas-1.1.9/mir-blas/source/mir/blas.d:385: error: undefined reference to 'cblas_dgemm'
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
---

This is Linux Manjaro with openblas package installed.

January 12, 2020
On Saturday, 11 January 2020 at 16:45:22 UTC, p.shkadzko wrote:
> I am trying to run example code from https://tour.dlang.org/tour/en/dub/lubeck
>
> ...
>
> This is Linux Manjaro with openblas package installed.

The Lubeck library depends on CBLAS, but the openblas package in the Arch repository is compiled without CBLAS. You can see that here (note the NO_CBLAS=1 parameter): https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/openblas

Try installing the cblas package: https://www.archlinux.org/packages/extra/x86_64/cblas/
January 13, 2020
On Sunday, 12 January 2020 at 13:07:33 UTC, dnsmt wrote:
> On Saturday, 11 January 2020 at 16:45:22 UTC, p.shkadzko wrote:
>> I am trying to run example code from https://tour.dlang.org/tour/en/dub/lubeck
>>
>> ...
>>
>> This is Linux Manjaro with openblas package installed.
>
> The Lubeck library depends on CBLAS, but the openblas package in the Arch repository is compiled without CBLAS. You can see that here (note the NO_CBLAS=1 parameter): https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/openblas
>
> Try installing the cblas package: https://www.archlinux.org/packages/extra/x86_64/cblas/

yeah, so I thought too but I have CBLAS installed as a distro package. I also have OpenBLAS installed instead of BLAS because BLAS was removed since it conflicts with OpenBLAS ¯\_(ツ)_/¯
March 10, 2020
On Monday, 13 January 2020 at 20:47:07 UTC, p.shkadzko wrote:
> On Sunday, 12 January 2020 at 13:07:33 UTC, dnsmt wrote:
>> On Saturday, 11 January 2020 at 16:45:22 UTC, p.shkadzko wrote:
>>> I am trying to run example code from https://tour.dlang.org/tour/en/dub/lubeck
>>>
>>> ...
>>>
>>> This is Linux Manjaro with openblas package installed.
>>
>> The Lubeck library depends on CBLAS, but the openblas package in the Arch repository is compiled without CBLAS. You can see that here (note the NO_CBLAS=1 parameter): https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/openblas
>>
>> Try installing the cblas package: https://www.archlinux.org/packages/extra/x86_64/cblas/
>
> yeah, so I thought too but I have CBLAS installed as a distro package. I also have OpenBLAS installed instead of BLAS because BLAS was removed since it conflicts with OpenBLAS ¯\_(ツ)_/¯

Figured it out by using mir-blas and linking it with openBlas on Linux.
You'll need openBlas and cblas installed.
dub.json needs "subConfigurations": {"mir-blas": "twolib"}
Then you can import blas functions like so import mir.blas : gemm;