go build - multiple cmd

2,109 views
Skip to first unread message

Carlos U. Cirello Filho

unread,
Feb 27, 2015, 6:13:36 PM2/27/15
to golan...@googlegroups.com
Hi,


Probably I am wrong - but I don't if I am wrong because I am doing something wrong or because the concept is wrong.

I have a project which will generate few binaries, therefore, I have few packages under cmd, like:

----> cmd/magic1
----> cmd/magic2


When I have only magic1 or magic2 under cmd, when I call:
$ go build ./cmd/... 

It generates the magic1 binary correctly. But when I have both, the same command generates no binary at all.

What is it wrong that I am doing/thinking?


Thanks,
        - CC

Mike Ossareh

unread,
Feb 27, 2015, 7:12:40 PM2/27/15
to Carlos U. Cirello Filho, golan...@googlegroups.com
This is by design and is documented here: http://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies

When the command line specifies a single main package, build writes the resulting executable to output. Otherwise build compiles the packages but discards the results, serving only as a check that the packages can be built.

To build both you can issue:

go build github.com/yatayatayta/cmd/magic1
go build github.com/yatayatayta/cmd/magic2

given the commands are under cmd/ you can readily script this so that you don't have to build each one by hand.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian Davis

unread,
Feb 27, 2015, 9:10:46 PM2/27/15
to golan...@googlegroups.com
Use go install instead
 
Ian

Dave Cheney

unread,
Feb 27, 2015, 9:17:37 PM2/27/15
to golan...@googlegroups.com


On Saturday, 28 February 2015 10:13:36 UTC+11, Carlos wrote:
Hi,


Probably I am wrong - but I don't if I am wrong because I am doing something wrong or because the concept is wrong.

I have a project which will generate few binaries, therefore, I have few packages under cmd, like:

----> cmd/magic1
----> cmd/magic2


When I have only magic1 or magic2 under cmd, when I call:
$ go build ./cmd/... 

It generates the magic1 binary correctly. But when I have both, the same command generates no binary at all.

You didn't include an example of trying this, and the results. That said, most of the go commands take multiple arguments, consider

% go build ./cmd/magic1 ./cmd/magic2

To echo what Ian also said, please prefer go install over go build, pretty much always.
Reply all
Reply to author
Forward
0 new messages