Good question - I recently ran into some weird behavior with printing from device kernels so maybe (very unlikely) there’s something I can connect here.
Looking at the debug call, I found that it writes to stdErr:
/// Print to stderr, unbuffered, and silently returning on failure. Intended
/// for use in "printf debugging." Use `std.log` functions for proper logging.
pub fn print(comptime fmt: []const u8, args: anytype) void {
stderr_mutex.lock();
defer stderr_mutex.unlock();
const stderr = io.getStdErr().writer();
nosuspend stderr.print(fmt, args) catch return;
}
It also looks like logging functions write to stdErr by default:
As soon as I put the -femit-h or getEmittedH() to generate the header, the build process gets terminated. Without those options, I could create the object file (well, no header file).
I was able to build a static library object and a header file by adding the linkLibC function in my build.zig file.
I tried to use it from Go, but got a bunch of error since it doesn’t know where the zig.h is. I added to link it, then it says ZIG_TARGET_MAX_INT_ALIGNMENT is undeclared.
I guess being able to build my code as library is the very first step, and now I need to dig deeper to do more. Since now I can generate the header that can print (zig-zig situation, not go-zig situation), let me close this topic.
Exact same problem here. Generating include files works well, but using CGO (which is importing zig.h) raises :
➜ cgo-zig CGO_CFLAGS="-I$ZIG_HOME/lib" go run .
# cgozig
In file included from ./cgozig.h:1,
from ./main.go:5:
../../../.local/share/zig/lib/zig.h: In function 'zig_int_bytes':
../../../.local/share/zig/lib/zig.h:1762:26: error: 'ZIG_TARGET_MAX_INT_ALIGNMENT' undeclared (first use in this function)
1762 | uint16_t alignment = ZIG_TARGET_MAX_INT_ALIGNMENT;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../.local/share/zig/lib/zig.h:1762:26: note: each undeclared identifier is reported only once for each function it appears in
As a workaround:
If you are on a 64-bit architecture add -DZIG_TARGET_MAX_INT_ALIGNMENT=16.
If you are on a 32-bit architecture add -DZIG_TARGET_MAX_INT_ALIGNMENT=8.
If you are targeting msvc add also -DZIG_TARGET_ABI_MSVC