go Verified current stable Not installed? Build Tools

Go / Run Go Link Tool

Run Go Link Tool

Runs the Go linker to create an executable binary from object files.

$
Terminal
go tool link <path/to/main.o>

When To Use

During the final build process to produce a distributable binary executable.

Pro Tip

Use `-o` parameter to specify the output binary name, especially when building optimized binaries for production.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
go tool link <path/to/main.o>

Anatomy of Output

Understanding the result

Linking path/to/main.o Link Action

Demonstrates which object file is currently being linked.

Successfully created executable binary: myprogram Executable Result

Indicates successful creation of the binary.

Power User Variants

Optimized versions

go tool link -o myprogram path/to/main.o

Specifies a custom output name for the binary.

go tool link -v path/to/main.o

Verbose output for the linking process.

Troubleshooting

Common pitfalls

cannot find main module

Solution: Verify that your project structure follows Go module guidelines.

object file does not exist

Solution: Check that the specified path to the object file is correct.

linker failed: exit status 1

Solution: Review the output for missing dependencies during the linking process.

Command Breakdown

What each part is doing

go
Base Command
The executable that performs this operation. Here it runs Go before the shell applies any redirect operators.
<path/to/main.o>
path to main.o
The value supplied for path to main.o.

Alternative Approaches

Comparable commands in other tools

Alternative build tools tools for the same job.