'How can I manually use go tool compile to compile multiple packages into a single executable file

For some reasons I need to use "go tool compile" to compile go files instead of using the automatic go build. "go tool compile" works fine with one file or multiple files in the same package, but if my project structure is like:

-package1
--p1.go
-package2
--p2.go
main.go
go.mod

where main.go uses symbols defined in package1 and package2. Then how am I supposed to use :go tool compile" to eventually get an executable program?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source