700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > go语言在windows编译在linux上运行的可执行程序

go语言在windows编译在linux上运行的可执行程序

时间:2018-11-04 03:41:40

相关推荐

go语言在windows编译在linux上运行的可执行程序

package mainimport ("fmt""os""os/exec")//filepath: 要编译的文件的路径func build(filepath string){_ = os.Setenv("CGO_ENABLED", "0")_ = os.Setenv("GOARCH", "amd64")_ = os.Setenv("GOOS", "linux")arg := []string{"build", filepath}if err := mand("go", arg...).Run(); err!=nil {fmt.Println("编译失败:", err)} else{fmt.Println("编译成功")}}func main() {build(`D:\gopathdir\src\httpproxy\main.go`) //被编译的go文件}

这是转载的,但是地址忘了。。。。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。