#How to build an executable for an ubuntu machine while on a Mac?

1 messages · Page 1 of 1 (latest)

tired dew
#

Im currently on a Mac and would like to build an executable that will run on an ubuntu machine. I know zig supports a lot of targets but I'm unsure on how to build for them. Im working with a tool that only supports ELF binaries.

golden spire
#

zig build -Dtarget=x86_64-linux-none

tired dew
#

thank you! how would i need to update my build.zig to accommodate -Dtarget=x86_64-linux-none?

#

when i run the above i get

#
joneric.cook@MBP zest % zig build -Dtarget=x86_64-linux-none
error: Invalid option: -Dtarget

Usage: /usr/local/Cellar/zig/0.10.1/bin/zig build [steps] [options]
#

dang - i get this error

#
joneric.cook@MBP zest % zig build example -Dexample=scouter -Dtarget=x86_64-linux-none
/Users/joneric.cook/github/zest/zig-out/bin/scouter: /Users/joneric.cook/github/zest/zig-out/bin/scouter: cannot execute binary file
The following command exited with error code 126 (expected 0):
cd /Users/joneric.cook/github/zest && /Users/joneric.cook/github/zest/zig-out/bin/scouter 
error: UnexpectedExitCode
/usr/local/Cellar/zig/0.10.1/lib/zig/std/build/RunStep.zig:277:17: 0x10b8987dc in runCommand (build)
                return error.UnexpectedExitCode;
                ^
/usr/local/Cellar/zig/0.10.1/lib/zig/std/build/RunStep.zig:183:5: 0x10b871af4 in make (build)
    try runCommand(
    ^
/usr/local/Cellar/zig/0.10.1/lib/zig/std/build.zig:3653:9: 0x10b7fdb4b in make (build)
        try self.makeFn(self);
        ^
/usr/local/Cellar/zig/0.10.1/lib/zig/std/build.zig:510:9: 0x10b7e6ecd in makeOneStep (build)
        try s.make();
        ^
/usr/local/Cellar/zig/0.10.1/lib/zig/std/build.zig:504:17: 0x10b7e6e27 in makeOneStep (build)
                return err;
                ^
/usr/local/Cellar/zig/0.10.1/lib/zig/std/build.zig:465:13: 0x10b7e6a68 in make (build)
            try self.makeOneStep(s);
            ^
/usr/local/Cellar/zig/0.10.1/lib/zig/build_runner.zig:225:21: 0x10b7ea219 in main (build)
            else => return err,
                    ^
error: the following build command failed with exit code 1:
/Users/joneric.cook/github/zest/zig-cache/o/a09344cc2c951018db7f3158496aec49/build /usr/local/Cellar/zig/0.10.1/bin/zig /Users/joneric.cook/github/zest /Users/joneric.cook/github/zest/zig-cache /Users/joneric.cook/.cache/zig example -Dexample=scouter -Dtarget=x86_64-linux-none
#

How to build an executable for an ubuntu machine while on Mac?

#

How to build an executable for an ubuntu machine while on a Mac?

unborn mesa
#

If you look at the error, it's erroring when trying to run the resulting executable

#

Which is obviously going to happen when you try to run a Linux binary on macOS

tired dew
#

Oh wow! Cool!

#

So then how would I only build it and not try and run it?

unborn mesa
#

Depends on how your build.zig works

#

Currently you've got a RunStep in there somewhere, you just need to not do that

tired dew
#

💯

silver thicket
#

-none isnt a valid abi on linux

unborn mesa
#

From a quick glance at your build.zig in the zest repo, just remove the example arg

silver thicket
#

you can leave it off or pass -musl since you're cross compiling

unborn mesa
#

The default is -none

#

So it's optional

#

But it is valid

silver thicket
#

the default is -gnu

unborn mesa
#

what

#

If you're compiling on a glibc system, the default target will be -gnu yes, but if you're specifying the target explicitly, it's not

tired dew
#

just doing zig build -Dtarget=x86_64-linux-none works - it just builds and thats it

#

thanks for the help!

unborn mesa
#

The default for cross-compiling is musl