Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 9189

Beginners • Re: Win 11 C Cross Compiler for Pi Zero ?

$
0
0
Hopefully this helps someone in the future

Find a cross compiler supporting the Pi Zero
Start at https://sourceforge.net/projects/raspbe ... ers/files/
Click on See All Activity and search for "Zero"
I chose to download the most modern build which for me was 14.2.0
(https://sourceforge.net/projects/raspbe ... z/download)

You will now see Downloads cross-gcc-14.2.0-pi_0-1.tar.gz

The following steps detail how to extract the cross compiler

Install Ubuntu and WSL on your PC

From here on in all commands are run in the Ubuntu shell

Open Ubuntu
Navigate to the Downloads folder: Ubuntu> cd mnt/c/Users/<your username>/Downloads
Unzip the archive: Ubuntu> tar -xvf cross-gcc-14.2.0-pi_0-1.tar.gz
Move the folder somewhere useful: Ubuntu> cp -r cross-pi-gcc-14.2.0-0 ~/x-tools
Make the files executable: Ubuntu> chmod -R +x ~/x-tools/bin
Add a path variable to the tools: Ubuntu> echo 'export PATH="$HOME/x-tools/bin:$PATH"' >> ~/.bashrc
Refresh path variable: Ubuntu> source ~/.bashrc

Quick tests:
Ubuntu> file arm-linux-gnueabihf-gcc -> Returned string should include: "ELF 64-bit"
Ubuntu> arm-linux-gnueabihf-gcc --version -> Returned string should include: "for GNU/Linux 3.2.0,"

Move to the source code folder because you are now ready to compile your code!
Ubuntu> arm-linux-gnueabihf-gcc helloworld.c -o helloworld

Move the generated output to the Raspberry Pi Zero: Ubuntu> scp helloworld pi@<IP Address>:/home/pi/
Connect to the Pi: Ubuntu> ssh pi@<IP Address>
Make the file executable: Ubuntu> chmod +x helloworld
Execute the file: Ubuntu> ./helloworld

Final Note
This question was originally posted hoping someone could provide the compile options to produce Pi Zero (armv6) code using the "official arm toolchains" (see https://developer.arm.com/downloads/-/a ... -downloads)
Some sources have suggested the modern toolchains ignore the -arch=arm6 compiler option, leading to "Segmentation fault" I was seeing
The above shows how to obtain a cross compiler specifically for the Pi Zero

Statistics: Posted by RatherBeSailing — Tue Dec 23, 2025 1:26 am



Viewing all articles
Browse latest Browse all 9189

Trending Articles