Created
September 7, 2021 11:12
-
-
Save McSinyx/2626241649133de7170139061702305f to your computer and use it in GitHub Desktop.
Zig extern struct recognized differently from Zig and C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Builder = @import("std").build.Builder; | |
pub fn build(b: *Builder) void { | |
const exe = b.addExecutable("test", "main.zig"); | |
exe.addIncludeDir("."); | |
exe.linkSystemLibrary("c"); | |
exe.setTarget(b.standardTargetOptions(.{})); | |
exe.setBuildMode(b.standardReleaseOptions()); | |
exe.install(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const makeFoo = @import("shared.zig").makeFoo; | |
const useFoo = @cImport(@cInclude("middle.h")).useFoo; | |
pub fn main() void { | |
useFoo(makeFoo()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MIDDLE_H | |
#define MIDDLE_H | |
#include "shared.h" | |
void useFoo(struct Foo foo) { } | |
#endif // MIDDLE_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment