Go-Goland可执行文件生成

2019-10-04  本文已影响0人  EamonYi

刚接触go语言,根据网上搜索的方法搭建好了环境,安装了IDE,今天卡在了可执行文件的生成上。下面描述下Goland生成可执行文件的配置情况。

环境情况

# go env 
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/usr/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/usr/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/T/go-build445033478=/tmp/go-build -gno-record-gcc-switches -fno-common"

代码情况

# helloworld.go
package main

import (
    "fmt"
    "time"
)
import "./config"

func main()  {
    fmt.Printf(config.Content)
    time.Sleep(1000*1000*1000)
}

# config.go
package config

var Content="HELLO WORLD"

目录结构如下:

- helloworld
    - src
        - config
            - config.go
        - helloworld.go

截图见附件image.png

build配置

Run -> Edit Configuration -> Go Build -> go build helloworld.go -> Go tool arguments

-o ../bin/哈哈哈哈

Apply -> OK

生成可执行文件

src目录右键 -> Run -> go build src/

新的目录结构如下:

- helloworld
    - bin
        - 哈哈哈哈
    - src
        - config
            - config.go
        - helloworld.go

截图见附件

上一篇 下一篇

猜你喜欢

热点阅读