#trying to call LAPACKE from zig keeps segfaulting

1 messages · Page 1 of 1 (latest)

fast frost
#

hey, im trying to call lapacke from zig, however no matter what i do it just always segfaults. i have tried linking both openblas and whatever version void ships, and ive tried both my own code and this snippet: https://ziggit.dev/t/problem-calling-lapacke-from-zig/7321, which was successfully calling lapacke according to the thread. trying to get a backtrace from lldb:

(lldb) bt
* thread #1, name = 'lapack-test', stop reason = signal SIGSEGV: address not mapped to object (fault address: 0x0)
  * frame #0: 0x0000000000000000

how i linked the library in my build.zig:

    //lib_mod.addIncludePath(.{ .cwd_relative = "/usr/include/" });
    //lib_mod.addLibraryPath(.{ .cwd_relative = "/usr/lib/" });
    //lib_mod.linkSystemLibrary("lapacke", .{ .needed = true, });
    //lib_mod.linkSystemLibrary("lapack", .{ .needed = true, });
    lib_mod.addIncludePath(b.path("src/deps/OpenBLAS/lapack-netlib/LAPACKE/include"));
    lib_mod.addObjectFile(b.path("src/deps/OpenBLAS/build/lib/libopenblas.a"));

how i used it:

const lapack = @cImport({
    @cInclude("lapacke.h");
});

...

    const cov_mat = [9]f64{
        cov_xx, cov_xy, cov_xz,
        cov_xy, cov_yy, cov_yz,
        cov_xz, cov_yz, cov_zz,
    };

    const eigenval_arr: [3]f64 = undefined;

    const success = lapack.LAPACKE_dsyev(
        101, // row major
        'V', // compute both eigenvalues and eigenvectors
        'U', // use upper triangle of matrix
        3, // matrix size
        &cov_mat, // matrix input, eigenvector output gets stored here too
        3, // leading dimension, == n
        &eigenval_arr, // output buffer for eigenvalues
    );

(+ the snippet from the link)

waxen orchid
#

You should use linkSystemLibrary for linking a library not built with build.zig. It also automatically links libc, did you linkLibC for lib_mod?

fast frost
#

yes, i did try linking libc, didnt change anything. also im trying to solve the segfault first, then i can get fancy with the build system

waxen orchid
#

i assumed the segfault originates from badly linked library, it doesn't even have a proper backtrace

fast frost
#

might be, but linking it both ways didnt help it

waxen orchid
#

are you building in debug mode? Weird that backtrace is empty

fast frost
#

yes

waxen orchid
#

What is the lapack-test anyway, the lib_mod?