Skip to content

zig build-exe: cross compiling does not works with simple hello world program #21770

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

Closed
mast3rz3ro opened this issue Oct 22, 2024 · 5 comments
Closed
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@mast3rz3ro
Copy link

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

~/ziglang $ ls
hello.zig

~/ziglang $ cat hello.zig
const std = @import("std");

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    try stdout.print("Hello, {s}!\n", .{"world"});
}

~/ziglang $ zig build-exe *.zig
warning: Encountered error: FileNotFound, 
falling back to default ABI and dynamic linker.

~/ziglang $ ls
hello  hello.o  hello.zig

~/ziglang $ file hello
hello: ELF 64-bit LSB executable, 
ARM aarch64, version 1 (SYSV), 
statically linked, with debug_info, not stripped

~/ziglang $ rm hello hello.o
~/ziglang $ zig build-exe *.zig -Dtarget=x86_64-windows
warning: Encountered error: FileNotFound, 
falling back to default ABI and dynamic linker.

~/ziglang $ ls
hello  hello.o  hello.zig

~/ziglang $ file hello
hello: ELF 64-bit LSB executable, 
ARM aarch64, version 1 (SYSV), 
statically linked, with debug_info, not stripped

Expected Behavior

Build success but output is unspecified target. i.e zig builds for system where it's currently running, rather than building for the specified target system.
I have check zig-build-system but I'm not sure if I quite understand it.

@mast3rz3ro mast3rz3ro added the bug Observed behavior contradicts documented or intended behavior label Oct 22, 2024
@Vexu
Copy link
Member

Vexu commented Oct 22, 2024

-Dtarget is used by the build system, for build-exe it declares a C macro. The flag you're looking for is --target.

@mast3rz3ro
Copy link
Author

The flag you're looking for is --target.

I have already tried that, and here is the output:

~/ziglang $ zig build-exe --target x86_64-windows hello.zig
error: unrecognized parameter: '--target'

@Vexu
Copy link
Member

Vexu commented Oct 22, 2024

My bad it's -target with one -.

@Vexu
Copy link
Member

Vexu commented Oct 22, 2024

Relevant issue #12341 (comment)

@Vexu Vexu closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2024
@mast3rz3ro
Copy link
Author

My bad it's -target with one -.

Yes, it's works:

~/ziglang $ ls
hello.zig

~/ziglang $ zig build-exe -target x86_64-windows hello.zig
~/ziglang $ ls
hello.exe      hello.pdb
hello.exe.obj  hello.zig

Thanks you!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants