0
点赞
收藏
分享

微信扫一扫

go 打包运行文件在windows,liunx运行

go 打包windows exe运行文件

	1,如果设置过其他系统环境 就要重新设置设置系统环境
		$env:GOOS = "windows"
		$env:GOARCH = "amd64"
	
	2,在主函数同目录进行打包  指定main.go为入口主函数
		go build -o goweb.exe main.go
		
		比如src/main.go
		就在src目录下进行打包,打包的exe文件就会在src目录下
		有静态资源文件夹,要放在exe同级目录下
			templates

	3,运行go 打包的 goweb.exe 使用cmd命令运行
	    //未指定主函数入口
		goweb.exe ./main.go
		//指定主函数入口
		goweb.exe
		程序就跑起来了

2,go打包 linux运行文件

	//如果设置过其他系统环境 就要重新设置设置系统环境
		$env:GOOS = "linux"
		$env:GOARCH = "amd64"
	
	//打包liunx可用文件 指定main.go为入口主函数
		go build -o myprogram main.go

	//运行start
		./myprogram 
	//后台start
		nohup ./myprogram &
	//stop
		pkill myprogram
举报

相关推荐

0 条评论