Generate an object file in elf format from a go file.

I was asked to produce an object file in elf format from a go file for a school project.
I’m new to the go language, so I have no idea what I’m doing.

Wikipedia: Executable and Linkable Format

(ELF, formerly named Extensible Linking Format), is a common standard file format for executable files, object code, shared libraries, and core dumps.

One obvious way is to compile on a Unix-like OS like Linux.

$ cat hello.go
package main

import "fmt"

func main() {
	fmt.Println("Hello, Gophers!")
}

$ go version
go version devel +249da7ec02 Thu Feb 11 18:04:49 2021 +0000 linux/amd64
$ go env GOOS
linux
$ go build -o hello hello.go
$ ./hello
Hello, Gophers!

$ objdump -f hello
hello:     file format elf64-x86-64
$

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.