Try your hand at a small test and take you step by step to implement your first Go program

Release: 2023-07-20 16:40:16
forward
903 people have browsed it

A little test, the first Go program

Every time you learn a new language, It started with Hello World.

OpenGoland, select the project directory to open, create a main.go file, the code is as follows:

package main //包名,main表示当前是一个可执行程序,一个目录下只能有一个main包名 import "fmt"//导入包 func main() {//main函数,程序入口函数 fmt.Println("Hello world") }
Copy after login

Perhaps you may not understand it, but don’t worry, type it first and it will run successfully. In Goland's code interface, right-click and run:

Try your hand at a small test and take you step by step to implement your first Go program


go build命令

上述,我们通过右击run main.go成功的运行了项目,但是go是静态编译语言,可以直接编译成xx.exe发给别人使用。cmd切换到项目目录下:

Try your hand at a small test and take you step by step to implement your first Go program

直接执行命令go build即可将当前main.go编译成可执行文件。

Try your hand at a small test and take you step by step to implement your first Go program

终端运行结果:

Try your hand at a small test and take you step by step to implement your first Go program

我们还可指定编译可执行文件的名字,需要-o参数,命令如下:

go build -o helloworld.exe
Copy after login

Try your hand at a small test and take you step by step to implement your first Go program

得到的文件如下:

Try your hand at a small test and take you step by step to implement your first Go program

The above is the detailed content of Try your hand at a small test and take you step by step to implement your first Go program. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:Go语言进阶学习
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!