Crosscompile for raspberry pi with sysroot

Hi,

I try to crosscompile a zig program on my amd64 development pc for my raspbery pi 3, model b (Cortex-A53).

test2.zig:

const std = @import("std");
const nc = @cImport(@cInclude("ncurses.h"));

pub fn main() void {
    _ = nc.initscr();
    _ = nc.printw("Hello World !!!"); // Print Hello World
    _ = nc.refresh(); // Print it on to the real screen
    _ = nc.getch(); // Wait for user input
    _ = nc.endwin(); // End curses mode
}

Standard compiling on my development pc works fine: zig build-exe test2.zig -lc -lncurses

When I’m now mounting the raspberry sysroot sshfs -o ro pi@raspberrypi.local:/ ./sysroot
cross-compiling fails:

zig build-exe test2.zig -target arm-linux-musleabihf -mcpu cortex_a53  -lc -lncurses --sysroot sysroot 
./test2.zig:27:12: error: C import failed
const nc = @cImport(@cInclude("ncurses.h"));
           ^
zig-cache/o/7fb3f7102b2fdf00f978c7be87a9ad5d/cimport.h:1:10: note: 'ncurses.h' file not found
#include <ncurses.h>

But ncurses.h is there:

ls sysroot/usr/include/ncurses.h -l
lrwxrwxrwx 1 root root 8 Dez 28  2017 sysroot/usr/include/ncurses.h -> curses.h

I’ve no more idea what to do, thanks for any hint.

zig version
0.10.0-dev.1738+6ae8fe193

Have you tried adding -Isysroot/usr/include/?
While this isn’t ideal, if it works, it should be fine as a work around. This could have something to do with zig not searching in the right places from “sysroot” with the arm-linux-musleabihf target, though don’t quote me on that, haven’t actually checked.

Ok, but to get rid of the ‘file not found’ messages I had to add some more pathes:

-Isysroot/usr/include -Isysroot/usr/include/arm-linux-gnueabihf/ -Lsysroot/usr/lib/arm-linux-gnueabihf

But finally I still get some linker errors and I don’t know what going on:

zig build-exe test2.zig -target arm-linux-musleabihf -mcpu cortex_a53  -lc -lncurses --sysroot sysroot -Isysroot/usr/include -Isysroot/usr/include/arm-linux-gnueabihf/ -Lsysroot/usr/lib/arm-linux-gnueabihf
ld.lld: error: undefined symbol: def_prog_mode
>>> referenced by lib_initscr.o:(initscr) in archive sysroot/usr/lib/arm-linux-gnueabihf/libncurses.a
>>> referenced by lib_set_term.o:(_nc_setupscreen) in archive sysroot/usr/lib/arm-linux-gnueabihf/libncurses.a
>>> referenced by lib_tstp.o:(handle_SIGTSTP) in archive sysroot/usr/lib/arm-linux-gnueabihf/libncurses.a

ld.lld: error: undefined symbol: __fprintf_chk
>>> referenced by lib_initscr.o:(initscr) in archive sysroot/usr/lib/arm-linux-gnueabihf/libncurses.a

ld.lld: error: undefined symbol: _nc_globals
>>> referenced by lib_initscr.o:(initscr) in archive sysroot/usr/lib/arm-linux-gnueabihf/libncurses.a
.....

Btw is it better to choose another target triple. e.g. arm-linux-gnueabihf?
But with gnueabihf I got some other error messages:

zig build-exe test2.zig -target arm-linux-gnueabihf -mcpu cortex_a53  -lc -lncurses --sysroot sysroot -Isysroot/usr/include -Isysroot/usr/include/arm-linux-gnueabihf/ -Lsysroot/usr/lib/arm-linux-gnueabihf
LLVM Emit Object... error(compilation): clang failed with stderr: In file included from /snap/zig/5064/lib/libc/glibc/sysdeps/arm/crti.S:44:
In file included from /snap/zig/5064/lib/libc/glibc/sysdeps/unix/sysv/linux/arm/sysdep.h:25:
In file included from /snap/zig/5064/lib/libc/glibc/sysdeps/unix/arm/sysdep.h:19:
/snap/zig/5064/lib/libc/glibc/sysdeps/arm/sysdep.h:25:11: fatal error: 'arm-features.h' file not found

error(compilation): /snap/zig/5064/lib/libc/glibc/sysdeps/arm/crti.S:1:1: unable to build C object: clang exited with code 1
error(compilation): clang failed with stderr: In file included from /snap/zig/5064/lib/libc/glibc/sysdeps/arm/crtn.S:38:
In file included from /snap/zig/5064/lib/libc/glibc/sysdeps/unix/sysv/linux/arm/sysdep.h:25:
In file included from /snap/zig/5064/lib/libc/glibc/sysdeps/unix/arm/sysdep.h:19:
/snap/zig/5064/lib/libc/glibc/sysdeps/arm/sysdep.h:25:11: fatal error: 'arm-features.h' file not found

error(compilation): /snap/zig/5064/lib/libc/glibc/sysdeps/arm/crtn.S:1:1: unable to build C object: clang exited with code 1
error: unable to build glibc CRT file: BuildingLibCObjectFailed
zig version
0.10.0-dev.1740+971ef7b9c

Ok, today I tried to cross compile a equivalent c programm to make sure that all includes and librarys are installed correctly.

#include <ncurses.h>

int main()
{	
	initscr();			/* Start curses mode 		  */
	printw("Hello World !!!");	/* Print Hello World		  */
	refresh();			/* Print it on to the real screen */
	getch();			/* Wait for user input */
	endwin();			/* End curses mode		  */

	return 0;
}

compiles fine on my development pc with
arm-linux-gnueabihf-gcc ncurses.c --sysroot=sysroot -mcpu=cortex-a53 -lncurses

and the resulting binary works on the rpi.

Maybe I use under zig the wrong target triple or it might be an issue, idk
Any help is appreciated, I’d love to switch to Zig