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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Checkpoints for Long MCP Requests: Only the User's Click Approves
  • Ampere PMU Profiler: A Guide to Microarchitecture Profiling
  • The Tectonic AI Platform: A Framework for Taming App Sprawl and Data Fragmentation
  • SelfService HR Dashboards with Workday Extend and APIs

Trending

  • Claude Code Superpowers: The 5-Tool Stack That Ends Limits and Context Amnesia
  • Hand an Issue to an Agent and Let It Run on Your Machine
  • Spring AI Migration: From the Vertex AI Gemini Module to the Google GenAI SDK
  • Using Middleware in LangChain: Recovering From Tool Failures

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

Cross compile go apps on Windows 10

By 
Mitch Dresdner
·
Jan. 10, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
9.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in


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

  • Checkpoints for Long MCP Requests: Only the User's Click Approves
  • Ampere PMU Profiler: A Guide to Microarchitecture Profiling
  • The Tectonic AI Platform: A Framework for Taming App Sprawl and Data Fragmentation
  • SelfService HR Dashboards with Workday Extend and APIs

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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