如何将外部可执行文件添加到Go项目

I am writing an application in Go. However on every platform my code will utilize external program compiled from another project in another language (e.g. C++ in Windows, Objective-C for Mac etc). This external executable is called with os/exec exec.Command function.

I can package my software with no problem, however one issue persists is that using go run will result in this file missing.

Is there a way to tell go that it should include external file (and preferably also build it from source) whenever I do $ go run myproj?

AFAIK, go run simply builds binary under a tmp directory, however it won't include any external files such as images etc. So for example when you have two files: $GOPATH/src/main/main.go and $GOPATH/ext-tool.bin and main.go content is:

package main

import "os/exec"

func main() {
    cmd := exec.Command("./ext-tool.bin")
    err := cmd.Run()
    if err != nil {
        os.Exit(1)
    }
}

One alternative would be to embed your executable in your application build.

This is done with go-bindata or its more recent successor unnoted/fileb0x.
There, you would have access to your embedded executable within an in-memory filesystem.