Hi,
On the MacOSX I want to do test cross-compilation of the very simple project where program should print on the screen gstreamer version.
This program is working on OSX but I can’t cross-compile it to the target aarch64-linux-gnu.
I have sysroot folder with all libraries and headers (it is working correctly with Make).
app.zig:
const std = @import("std");
const c = @cImport({
@cInclude("gst/gst.h");
});
pub fn main() !void {
std.debug.print("hello world \n", .{});
var argc: c_int = 0;
var argv: [*c][*c]u8 = null;
c.gst_init(&argc, &argv);
var major: c.uint = 0;
var minor: c.uint = 0;
var micro: c.uint = 0;
var nano: c.uint = 0;
c.gst_version(&major, &minor, µ, &nano);
if (nano == 1) {
std.debug.print("Gstreamer Development Release: {d}.{d}.{d}.{d}\n", .{ major, minor, micro, nano });
} else {
std.debug.print("Gstreamer Development Release: {d}.{d}.{d}\n", .{ major, minor, micro });
}
}
build.zig ← this idea is the main target of my interest of ZIG
const std = @import("std");
pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "gst_version",
.root_source_file = .{ .path = "app.zig" },
//.target = b.host,
.target = b.resolveTargetQuery(.{
.cpu_arch = .aarch64,
.os_tag = .linux,
.abi = .gnu,
}),
});
exe.addLibraryPath(.{ .path = "./usr/lib/aarch64-linux-gnu" });
exe.addIncludePath(.{ .path = "/usr/include" });
exe.addIncludePath(.{ .path = "/usr/include/gstreamer-1.0" });
exe.linkSystemLibrary("gstreamer-1.0");
//exe.linkSystemLibrary("gstreamer");
exe.linkLibC();
b.installArtifact(exe);
}
zig build --summary all --sysroot sysroot
And I got:
app.zig:3:11: error: C import failed
const c = @cImport({
^~~~~~~~
referenced by:
main: app.zig:11:5
callMain: /opt/homebrew/Cellar/zig/0.12.0/lib/zig/std/start.zig:511:32
remaining reference traces hidden; use '-freference-trace' to see all reference traces
/Users/user/cross-cpp/zig-cache/o/ce1bb7180e1e4ac4e765f24ddfaa1a73/cimport.h:1:10: error: 'gst/gst.h' file not found
#include <gst/gst.h>
In many places I see that people correctly can cross compile but the programs are very simple without sysroot of the target.
I really want to make this real, because … cmake… I want this zig build.
Best regards and thanks for help.