开发者学堂课程【Go 语言核心编程 - 基础语法、数组、切片、Map: G0 语言编译运行说明】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/625/detail/9499
G0 语言编译运行说明
内容介绍:
一、什么是编译
二、编译和运行说明
一、什么是编译
atguigu@ubuntu:~/gocode$ go build hello.go
atguigu@ubuntu:~/gocode$ is -lh
总用量 1.8M
-rwxrwxr-x 1 atguigu atguigu 1.8M 20 19:50 hello
-rw-rw-r-- 1 atguigu atguigu
72 Apr 20 19:25 hello.go
二、编译和运行说明
1) 有了 go 源文件,通过编译器将其编译成机器可以识别的二进制码文件。
2) 在该源文件目录下,通过 go build 对 hello.go 文件进行编译。可以指定生成的可执行文件名,在 windows 下必须是 .exe 后缀。
(用鼠标把目录选中,输入 cmd ,回车,可以直接进入)
代码 go build -o myhello.exe hello.go
此时生成文件名为 myhello.exe
3) 如果程序没有错误,没有任何提示,会在当前目录下会出现一个可执行文件 ( windows 下是 .exe Linux 下是一个可执行文件),该文件是二进制码文件,也是可以执行的程序。
4)如果程序有错误,编译时,会在错误的那行报错。有助于程序员调试错误。
代码
package main
import “fmt”
func main() {
fmt.Println(“hello,world !”)
// shift+alt+ 向下箭头,
向下复制行
fmt.Printnl(“hello,world !”)
//这里会提示错误 undefined: fmt.Printnl
mt.Println(“hello,world !”)
}
编译后,也会提示错误 .
\hello.go:7:2 undefined: fmt.Printnl
7 表示第七行代码
D: \progrgof iles\gocode >go run hello.go
# connand-line-argunents
.\hello.go:9:2: undefined: fnt.Print In2
5)运行有两种形式
什么是运行
atguigu@ubuntu:~/gocode$
atguigu@ubuntu:~/gocode$ ./hello
hello,world!
atguigu@ubuntu:~/gocode$
D:\progranfiles\gocode>hello.exe
hello,world!
1) 直接运行生成的可执行 Go 程序,比如 helo.exe
2) 通过运行工具 go run 对源代码文件进行运行。
vs code 如何调整字体大小:
点文件——首选项——设置,
点击//以像素为单位控制字号下的笔,点编辑,修改右侧字体大小,用右侧填写的设置覆盖默认的设置,文件保存后,字体被改变。