1、安装go1.15.3.windows-amd64,环境变量:GOROOT=C:\Go、GOPATH=C:\mygopath
2、安装goland-2020.2.3.exe,利用其Terminal窗口代替windows命令行 cmd
3、安装mingw5.1.6,修改环境变量:用户变量Path中增加C:\MinGW\bin
并将C:\MinGW\bin\mingw32-make.exe复制、粘贴、改名为make.exe
4、Go设置代理环境(便于无障碍下载github网站上的go项目):
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
5、在goland的Terminal窗口下载go项目frp
go get -u github.com/fatedier/frp
(get加上-u可以利用网络来更新已有的代码包及其依赖包)
下载后frp所在的文件夹为
C:\mygopath\pkg\mod\github.com\fatedier\frp@v0.34.1
6、编译go项目frp
运行
cd C:\mygopath\pkg\mod\github.com\fatedier\frp@v0.34.1
make
结果如下:
C:\mygopath\pkg\mod\github.com\fatedier\frp@v0.34.1>make
go fmt ./...
go: downloading github.com/fatedier/golib v0.1.1-0.20200901083111-1f870741e185
go: downloading k8s.io/apimachinery v0.18.3
go: downloading golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
go: downloading github.com/onsi/gomega v1.10.1
go: downloading golang.org/x/time v0.0.0-20191024005414-555d28b269f0
go: downloading github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
go: downloading github.com/coreos/go-oidc v2.2.1+incompatible
go: downloading github.com/prometheus/client_golang v1.4.1
go: downloading github.com/rakyll/statik v0.1.1
go: downloading github.com/rodaine/table v1.0.0
go: downloading github.com/onsi/ginkgo v1.12.3
go: downloading gopkg.in/square/go-jose.v2 v2.4.1
go: downloading github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c
go: downloading golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7
go: downloading github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible
go: downloading github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec
go: downloading github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb
go: downloading github.com/google/uuid v1.1.1
go: downloading github.com/gorilla/mux v1.7.3
go: downloading golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
go: downloading github.com/gorilla/websocket v1.4.0
go: downloading github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35
go: downloading github.com/beorn7/perks v1.0.1
go: downloading golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
go: downloading github.com/cespare/xxhash/v2 v2.1.1
go: downloading github.com/pires/go-proxyproto v0.0.0-20190111085350-4d51b51e3bfc
go: downloading golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980
go: downloading gopkg.in/yaml.v2 v2.3.0
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/prometheus/common v0.9.1
go: downloading github.com/golang/protobuf v1.4.2
go: downloading github.com/pkg/errors v0.8.1
go: downloading github.com/golang/snappy v0.0.1
go: downloading github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
go: downloading github.com/klauspost/reedsolomon v1.9.1
go: downloading google.golang.org/protobuf v1.23.0
go: downloading github.com/klauspost/cpuid v1.2.0
go: downloading github.com/templexxx/xor v0.0.0-20170926022130-0af8e873c554
go: downloading golang.org/x/text v0.3.2
go: downloading github.com/spf13/cobra v0.0.3
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
go: downloading github.com/tjfoc/gmsm v0.0.0-20171124023159-98aa888b79d8
go: downloading github.com/templexxx/cpufeat v0.0.0-20170927014610-3794dfbfb047
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/inconshreveable/mousetrap v1.0.0
env CGO_ENABLED=0 go build -ldflags "-s -w" -o bin/frps ./cmd/frps
'env' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
make: *** [frps] Error 1
出错处理:
1)手工设置环境变量CGO_ENABLED,在在goland的Terminal窗口输入:
go env -w CGO_ENABLED=0
2)修改Makefile
去掉只读属性,删除文件中的env CGO_ENABLED=0
3)再次make,顺利通过编译。结果如下:
C:\mygopath\pkg\mod\github.com\fatedier\frp@v0.34.1>make
go fmt ./...
go build -ldflags "-s -w" -o bin/frps ./cmd/frps
go build -ldflags "-s -w" -o bin/frpc ./cmd/frpc
C:\mygopath\pkg\mod\github.com\fatedier\frp@v0.34.1>
在C:\mygopath\pkg\mod\github.com\fatedier\frp@v0.34.1\bin文件夹可以找到两个文件
frpc
frps
改为frpc.exe和 frps.exe即可使用。