I'm trying to create a go.o object file that I'll link using external linker. I followed the gopher-os procedure to extract object file.
main.go:
package main
func main() {
}
Makefile:
go.o:
mkdir -p build
GOARCH=386 GOOS=linux CGO_ENABLED=0 go build -n main.go 2>&1 | sed \
-e "1s|^|set -e\n|" \
-e "1s|^|export GOOS=linux\n|" \
-e "1s|^|export GOARCH=386\n|" \
-e "1s|^|export CGO_ENABLED=0\n|" \
-e "1s|^|WORK='build/'\n|" \
-e "1s|^|alias pack='go tool pack'\n|" \
-e "/^mv/d" \
-e "s|-extld|-tmpdir='build/' -linkmode=external -extldflags='-nostdlib' -extld|g" \
| sh 2>&1 | sed -e "s/^/ | /g"
When I invoke make go.o
, I get the following message in the terminal:
| loadinternal: cannot find runtime/cgo
| /usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000008049000
The go.o file does get created in the build/
directory, but any further use of that file does not lead to successful results further in my work.
I have tried setting CGO_ENABLED
to 0
and 1
but it doesn't seem to affect anything.