2

I need to compile programs within golang in golang. Is there any native form without using exec.Command("go","build") ?

3
  • 3
    The go tool is how you compile Go code. Commented Jun 5, 2019 at 11:01
  • Whatever you are trying to do, it will mostly be faster, reliable, secure and maintainable if you just write the code in your application itself, or may be import it as a library/dependency. Compiling code on the go isn't a good idea, unless you are trying to make something like "Go playground". Commented Jul 14, 2019 at 20:04
  • 3
    While it may be effectively impossible, I too would like to do this, so I don't really get the hostility to the question (and this was my first Google hit looking into the possibility). My use-case is to embed a "go playground" in a standalone application that would run places where the go tool might not be installed. Commented Oct 21, 2019 at 18:53

2 Answers 2

3

Unfortunately I think using exec.Command is your best bet to harness the tools written by the Go community in order to compile your go programs within a go program.

Sign up to request clarification or add additional context in comments.

Comments

0

You can try this

First set the $GOPATH

then set the $GOBIN

after that you can run go build or go get..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.