DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The Tectonic AI Platform: A Framework for Taming App Sprawl and Data Fragmentation
  • SelfService HR Dashboards with Workday Extend and APIs
  • How We Reduced LCP by 75% in a Production React App
  • Shipping GenAI Into an Existing App: How to Integrate AI Features Without Rewriting Your Stack

Trending

  • Build Your Own Local AI QA Engineer With Docker, Ollama, LibreChat, and Playwright MCP
  • Calling GCP From AWS Without Static Keys Using Open-Source MultiCloudJ
  • How to Build Living AI Coding Assistants With Quarkus Agent MCP
  • Why Standard Test Automation Misses the Failures That Matter in AI Agent Systems

Cross compile go apps on Windows 10

By 
Mitch Dresdner user avatar
Mitch Dresdner
·
Jan. 10, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
9.6K Views

Join the DZone community and get the full member experience.

Join For Free


I wanted to try cross-compiling gotop for the Raspberry Pi 4 using my Windows 10 Laptop. It threw me an error (Yikes!):

Shell
xxxxxxxxxx
1
 
1
logging_other.go:11:2: undefined: syscall.Dup2


It was getting late, and I needed to get some grilling done. So I decided instead (for now) to go get it, build it, and install it on my Pi 4 and play with a simpler task: cross-compiling for the ARM processor.

Shell
xxxxxxxxxx
1
 
1
# go get gotop locally on my Pi 4
2
go get github.com/cjbassi/gotop
3

          
4
go build
5

          
6
go install
7

          
8
# See it running below


Here's gotop, showing load across 4 CPU Cores, memory, and process utilization. If you type the "?" operator it will show you the key bindings, and if you know vim, most of them will be familiar to you.

Now that I have gotop up and running (I hope to use it to see how loaded it gets using picamara in a VNC session), I'll show the important parts of cross-compiling from Windows 10 to the Pi 4.

You may also like: Cross-Compilation With Buildroot.

Here's a simple hello world that we'll cross-compile. I'll call the file howdy.go:

Go
xxxxxxxxxx
1
 
1
package main
2

          
3
import "fmt"
4

          
5
func main() {
6
    fmt.Println("Howdy do")
7
}


The Pi 4 uses an ARM 7 processor, but you can check this by running the uname command.

Shell
xxxxxxxxxx
1
 
1
uname -a
2

          
3
Linux my-host 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux


Compile the sample howdy.go for Linux, specifying the ARM 7 processor:

Shell
xxxxxxxxxx
1
 
1
REM Compile for ARM 7 processor
2
c:> env GOOS=linux GOARCH=arm GOARM=7 go build
3

          
4
REM copy to Pi4
5
scp howdy pi@my-host:~/


Run it on your Pi 4, making sure the permissions are good to run it.

Shell
xxxxxxxxxx
1
 
1
chmod 755 howdy
2

          
3
./howdy

I hope you found this post both practical and interesting!


Further Reading

  • An ARM Image With Buildroot.
  • Be Aware: Floating Point Operations on ARM Cortex-M4F.
  • Windows 10 Will Ship With a Full Linux Kernel.
app

Opinions expressed by DZone contributors are their own.

Related

  • The Tectonic AI Platform: A Framework for Taming App Sprawl and Data Fragmentation
  • SelfService HR Dashboards with Workday Extend and APIs
  • How We Reduced LCP by 75% in a Production React App
  • Shipping GenAI Into an Existing App: How to Integrate AI Features Without Rewriting Your Stack

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook