-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
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
Linking with objective-c causes bus error on macOS #6337
Comments
Just tried this with Zig version Edit: const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
var exe = b.addExecutable("zig-macos-objc", "src/main.zig");
// Compiles the objective-c code into `./objc.o`
var compile_objc = b.addSystemCommand(&[_][]const u8{
"clang",
"-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk",
"-c", "src/objc.m",
});
exe.addFrameworkDir("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/");
exe.linkFramework("Foundation");
exe.addObjectFile("./objc.o");
exe.step.dependOn(&compile_objc.step);
// Everything from here on is as emitted by `zig init-exe`
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
} |
Hmm, I'm surprised this works for you @fabioarnold. I get a linker error:
Are you using the system linker by any chance, i.e., have this var set |
You're right, sorry! |
Thanks for confirming @fabioarnold! |
Fixed in #9229. |
I'm trying to write some macOS-specific code in objective-c and include that in my Zig application. However, the following simple setup causes a crash when building.
build.zig
src/objc.m
src/main.zig
This is what caused the crash according to the macOS Console:
Zig-Version:
0.6.0+c49435f76
macOS Version:
10.15.6
If any other information like the output from
zig build --verbose-link
is needed I can add that as well.Edit: By manually using
ld
I was able to link a working binary.The text was updated successfully, but these errors were encountered: