We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running into a strange segfault when using @cImport:
Create sample.h in a folder:
sample.h
typedef struct somecstruct { usize foo; } somecstruct;
And then create foo.zig as:
foo.zig
const std = @import("std"); const sample = @cImport({ @cInclude("sample.h"); }); pub const Foo = struct { Bar: sample.somecstruct }; pub fn main() !void { var d = @intCast(usize, 37); std.debug.warn("Converted {}\n", .{d}); var x = .{ .Bar = .{ .foo = d } }; }
Run with:
zig run -lc foo.zig -I./
Produces:
> zig run -lc foo.zig -I./ Converted 37 Segmentation fault at address 0x201d90 /home/m/foo.zig:13:33: 0x203ce2 in main (foo) var x = .{ .Bar = .{ .foo = d } }; ^ /usr/lib/zig/std/start.zig:345:37: 0x204031 in std.start.main (foo) const result = root.main() catch |err| { ^ zsh: abort zig run -lc foo.zig -I./
Tested on musl / Alpine linux with zig version:
> zig version 0.8.0-dev.1343+3c0238e73
The text was updated successfully, but these errors were encountered:
Duplicate of #3915.
Adding a type to x makes this work just fine:
x
pub const Foo = struct { Bar: sample.somecstruct }; pub fn main() !void { var d = @intCast(usize, 37); std.debug.warn("Converted {}\n", .{d}); var x: Foo = .{ .Bar = .{ .foo = d } }; }
Sorry, something went wrong.
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
Running into a strange segfault when using @cImport:
Create
sample.h
in a folder:And then create
foo.zig
as:Run with:
Produces:
Tested on musl / Alpine linux with zig version:
The text was updated successfully, but these errors were encountered: