Go Build executable

(Charles N. Cordaro) #1


I have a source program with a path of  "C:\Users\User\go\src\awesomeproject\pgmxyz"

How do I construct the Build statement to compile the pgmxyz program ?
Where does the compiler put the executable program ?

(Luis) #2

go to the “C:\Users\User\go\src\awesomeproject\pgmxyz” folder and run:
go build “file1.go” “file2.go”…
It will create and exe file in the same folder.

(Charles N. Cordaro) #3

What do I type for file1 and file2 ? the complete path for pgmxyz ?

(Luis) #4

you have to put the file name. for example:
go build “main.go”

Or more if you have more files, you have to put the names of all the files used in your code, for example:
go build “main.go” “package1.go"

its like the run command.
Go run main.go
replace the “run” word with “build”

(nathankerr) #5

go build defaults to compiling all the .go files in the current directory. You don’t need to list them.

(Charles N. Cordaro) #6

Hi Luis

I went to the folder where my pgmxy is.  Where  do I enter the 

go build pgmxy.go command ? Do I use Window’s run option ?

(Norbert Melzer) #7

You use the terminal of your choice.

This can be cmd.exe, powershell or any other you like or prefer.