Sorry for this super basic question.
I’m coming to Mojo from a primarily Python background. My only real exposure to a compiled language is Rust (of which I’m very beginner). In Rust, I use Cargo to init
, add
, run
, build
, Rust code. So I thought with Mojo, Magic filled this role? However, this evening while playing/testing, I found there is no magic build
command. I then tried to do mojo build
and got prompted that command “mojo” not found.
I’m running Mojo in WSL (Ubuntu) on Win 11 and using VS Code. When I use the “play” button in VS Code, things run just fine, but I don’t think it’s building an executable.
How do you turn a .mojo file into an executable?
Initialise a “magic shell” first. Then you can run mojo build)
@lesoup-mxd Thank you! That worked!
I had a few follow-up errors that I was able to solve. I’m going to share them here, in case someone searches.
After entering the shell magic shell
I ran the following:
mojo build main.mojo
But got the following error:
mojo: error: unable to find suitable c++ compiler for linking
This is because I was missing the build-essentials
on Ubuntu. Which I installed:
sudo apt-get install build-essential
I tried to do mojo build main.mojo
again and got the following errors:
/usr/bin/ld: cannot find -lz: No such file or directory
/usr/bin/ld: cannot find -ltinfo: No such file or directory
collect2: error: ld returned 1 exit status
mojo: error: failed to link executable
Which was solved by installing zlib1g-dev
and libtinfo-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libtinfo-dev
Thanks again for the help! and I hope this might help others in the future. 
2 Likes
Hi @AffableHoneyBadger thanks very much for reporting back the fix, they are working on adding these dependencies to the sandboxed environment on Linux so you don’t have to install them yourself. Will reply to this thread when that’s resolved.
1 Like
That’s great to hear! Thanks @jack.clayton !