Go Build executable

Hello

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 ?

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.

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

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”

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

1 Like

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 ?

You use the terminal of your choice.

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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.