go run:go run 编译并直接运行程序,它会产生一个临时文件(但不会生成 .exe 文件),直接在命令行输出程序执行结果,方便用户调试。

go build:go build 用于测试编译包,主要检查是否会有编译错误,如果是一个可执行文件的源码(即是 main 包),就会直接生成一个可执行文件。

go install:go install 的作用有两步:第一步是编译导入的包文件,所有导入的包文件编译完才会编译主程序;第二步是将编译后生成的可执行文件放到 bin 目录下($GOPATH/bin),编译后的包文件放到 pkg 目录下($GOPATH/pkg)。
---------------------
作者:路人1994
来源:CSDN
原文:https://blog.csdn.net/zyz770834013/article/details/78656985
版权声明:本文为博主原创文章,转载请附上博文链接!

export GOROOT="/usr/lib/go-1.9/"
export PATH="$PATH:$GOROOT/bin"
export GOPATH=~/go/

复制一份

/home/hu/gogo/frp/vendor/golang.org

到 ~/go/src

*@*:~/go/src$ ls
github.com golang.org

*@*:~/gogo/frp$ env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o ./frpc_windows_amd64.exe ./cmd/frpc
*@*:~/gogo/frp$ env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o ./frps_windows_amd64.exe ./cmd/frps

客户端编译不过?

执行

*@*:~/gogo/frp$ go get github.com/inconshreveable/mousetrap
*@*:~/gogo/frp$ gp get github.com/spf13/cobra

最近编译不过

发现缺少库

下载地址 。

https://github.com/golang/go

下面那句是编辑

leafpad ~/.bashrc

export GOROOT=$HOME/go

export GOPATH=$HOME/go

export PATH=$GOROOT/bin:$GOPATH/bin:$PATH

source ~./bashrc

上面那句是刷新

https://glide.sh/

root@11:~/gopath/src/github.com/fatedier/frp# glide install
[WARN]The name listed in the config file (github.com/fatedier/frp) does not match the current location (.)
[INFO]Downloading dependencies. Please wait...
[INFO]--> Fetching github.com/pmezard/go-difflib
[INFO]--> Fetching github.com/rakyll/statik
[INFO]--> Fetching github.com/rodaine/table
[INFO]--> Fetching github.com/stretchr/testify
[INFO]--> Fetching github.com/templexxx/reedsolomon
[INFO]--> Fetching github.com/fatedier/kcp-go
[INFO]--> Fetching github.com/templexxx/cpufeat
[INFO]--> Fetching github.com/templexxx/xor
[INFO]--> Fetching github.com/tjfoc/gmsm
[INFO]--> Fetching github.com/armon/go-socks5
[INFO]--> Fetching github.com/julienschmidt/httprouter
[INFO]--> Fetching github.com/davecgh/go-spew
[INFO]--> Fetching github.com/golang/snappy
[INFO]--> Fetching github.com/docopt/docopt-go
[INFO]--> Fetching github.com/gorilla/websocket
[INFO]--> Fetching github.com/fatedier/beego
[INFO]--> Fetching github.com/klauspost/reedsolomon
[INFO]--> Fetching github.com/pkg/errors
[INFO]--> Fetching github.com/klauspost/cpuid
[INFO]--> Fetching github.com/vaughan0/go-ini
[INFO]--> Fetching github.com/xtaci/kcp-go
[INFO]--> Fetching github.com/xtaci/smux
[INFO]--> Fetching golang.org/x/crypto
[INFO]--> Fetching golang.org/x/net
[WARN]Unable to checkout golang.org/x/crypto
[ERROR]Update failed for golang.org/x/crypto: Cannot detect VCS
[WARN]Unable to checkout golang.org/x/net
[ERROR]Update failed for golang.org/x/net: Cannot detect VCS
[ERROR]Failed to install: Cannot detect VCS
Cannot detect VCS

[common]
#server_addr一定要写域名形式,不要直接写IP地址
server_addr = frp2.chuantou.org
server_port = 7000
privilege_token = www.xxorg.com
protocol = kcp
# 标注你的代理名字,随便选择一个跟别人不一样即可
user = myname [askm2]
type = http
local_ip = 127.0.0.1
local_port = 80
# 选择一个可用的子域名,你的访问地址将会是http://xxorg.frp2.chuantou.org
subdomain = askm2 [common]
server_addr = frpzj.lu8.win
server_port = 7000
privilege_token = frp888
log_file = frpc.log
log_level = info
log_max_days = 3 [web]
privilege_mode=true
type = http
local_port = 2222
local_ip = 127.0.0.1
custom_domains = ask.frp.lu8.win [chiness中国_50002]
privilege_mode = true
type = tcp
local_ip = 127.0.0.1
local_port = 80
use_gzip = true
use_encryption = true
authentication_timeout = 0
remote_port = 50002 [chiness中国http_50003]
privilege_mode = true
type = tcp
local_ip = 192.168.2.1
local_port = 80
authentication_timeout = 0
remote_port = 50003 [common]
server_addr = frpzj.lu8.win
server_port = 7000
privilege_token = frp888
log_file = frpc.log
log_level = info
log_max_days = 3 [chiness中国_50002]
privilege_mode = true
type = tcp
local_ip = 127.0.0.1
local_port = 5900
use_gzip = true
use_encryption = true
authentication_timeout = 0
remote_port = 50002 [chiness中国http_50003]
privilege_mode = true
type = tcp
local_ip = 127.0.0.1
local_port = 80
use_gzip = true
use_encryption = true
authentication_timeout = 0
remote_port = 50003

如何压缩Golang 编译出的可执行文件大小

先给结论:可以减少到原来的29%

最近在写一个TLScat小工具 Github.com/mengzhuo/tlscat 源文件仅仅2KB不到,但是用 go build tlscat.go 编译出来的有4.6MB!

后来发现这个Golang的1.5才会解决的问题 Issue #6853 all: binaries too big and growing 可是,我就不信这个邪,于是搜索到了go build的一些用法 go build -ldflags "-s -w" '-s' 相当于strip掉符号表, 但是以后就没办法在gdb里查看行号和文件了。 '-w' flag to the linker to omit the debug information 告知连接器放弃所有debug信息 这样一来就只有3MB了

然后发现在Mac平台下,还有upx这样神一般的存在。

UPX achieves an excellent compression ratio and offers very fast decompression.

简而言之,upx就是对可执行文件进行压缩,然后可以已极快的速度解压并运行

可以用brew快速安装upx brew install upx upx 可执行文件

Golang在windows下交叉编译linux程序

1、下载相关程序。

  Golang下载:http://www.golangtc.com/download

  Git下载:http://git-scm.com/download/

  TDM-GCC下载:http://tdm-gcc.tdragon.net/download

2、Go编译环境配置

  安装 TDM-GCC,程序会自动设置PATH环境变量,如果没有设置成功请手动设置。

  安装Go,安装完后需要设置GOROOT,GOPATH,GOBIN,PATH环境变量,

  其中  

  GOROOT为你的Go安装跟目录

  GOPATH为你go程序开发目录,go get后的包也会下载到该目录。

  GOBIN为你的go运行目录,运行 go install 命令后,程序会被安装到该目录。

  PATH为你Go程序根目录,用于能够通过控制台调用go命令。

3、配置交叉编译环境

  在Go根目录下的src目录,新建一个build.bat文件,并复制内容如下:

set CGO_ENABLED=0
set GOROOT_BOOTSTRAP=C:/Go
::x86块
set GOARCH=386
set GOOS=windows
call make.bat --no-clean set GOOS=linux
call make.bat --no-clean set GOOS=freebsd
call make.bat --no-clean set GOOS=darwin
call make.bat --no-clean
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::x64块
set GOARCH=amd64
set GOOS=linux
call make.bat --no-clean
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::arm块
set GOARCH=arm
set GOOS=linux
call make.bat --no-clean
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: set GOARCH=386
set GOOS=windows
go get github.com/nsf/gocode
pause

  我的Go程序版本是1.6,需要设置GOROOT_BOOTSTRAP变量为Go的安装目录,否则执行时会报错。

  然后运行build.bat,等待结束。

  该程序会编译其他平台编译Go需要的库和编译文件。

  完成后,在cmd命令行下依次执行:

  set GOOS=linux

  set GOPACH=amd64

  go build -o -x APPNAME main.go

  编译后的文件会出现在main.go相应的目录下。

现在go 的跨平台编译比较简单了,
set GOARCH=amd64
set GOOS=linux
然后就可以了, go build出来的就是linux 64 位的可执行程序了

ubuntu frp 自编译。本文不能按顺序来 请自己理解的更多相关文章

  1. Ubuntu 15.04 编译UE4 for Linux版

    源 起 Unreal Engine 4 是全球最先进的Realtime Illumination & Physical 引擎: 长期以来,UE4都只有Windows版和Mac版,今年终于向Li ...

  2. 对<< ubuntu 12.04编译安装linux-3.6.10内核笔记>>的修正

    前题: 在前几个月的时候,写了一篇笔记,说的是kernel compile的事情,当时经验不足,虽说编译过了,但有些地方写的有错误--因为当时的理解是有错误的.今天一一更正,记录如下: 前文笔记链接: ...

  3. Ubuntu通过源代码编译安装Octave 4.0

    本教程/笔记,意在指导在Ubuntu及其它Linux系统上怎样通过源代码安装Octave. Octave简单介绍 Octave是GNU旗下取代matlab的数学工具软件,语法与matlab高度兼容.而 ...

  4. ubuntu下boost编译安装

    ubuntu下boost编译安装 boost 安装 1.依赖安装 apt-get install mpi-default-dev libicu-dev python-dev python3-dev l ...

  5. ubuntu下如何编译C语言

    ubuntu下如何编译C语言     如果没有gcc编译器的话,使用以下命令获取 ~# sudo apt-get install gcc同时要下载辅助工具 ~# sudo apt-get instal ...

  6. Ubuntu 14.04 编译 Android 4.2.2 for Tiny4412

    . . . . . 在学校里是用 Redhat 6.4 编译的 Android 4.2.2 很顺利,把源码包拷贝到笔记本上的 Ubuntu 14.04 上再编译遭遇了各种坑,所以便有了这篇博客记录解决 ...

  7. Ubuntu 18.04 编译 ijkplayer

    Ubuntu 18.04 编译 ijkplayer 1. 配置安装源 https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu 2. 配置好安装源后,安装一些组 ...

  8. 在Ubuntu安装go编译环境

    在Ubuntu安装go编译环境 好记性不如烂笔头,所以趁热打铁记录下golang编译环境的安装过程. 首先下载一些依赖包: sudo apt-get install bison ed gawk gcc ...

  9. Ubuntu/CentOS下编译Nginx最基本参数

    Ubuntu/CentOS下编译Nginx安装基本参数,做个记录: groupadd www useradd -g www www ./configure --user=www --group=www ...

随机推荐

  1. 剑指OFFER之二叉树的镜像(九度OJ1521)

    题目描述: 输入一个二叉树,输出其镜像. 输入: 输入可能包含多个测试样例,输入以EOF结束.对于每个测试案例,输入的第一行为一个整数n(0<=n<=1000,n代表将要输入的二叉树节点的 ...

  2. [Xcode 实际操作]九、实用进阶-(15)屏幕截屏:截取当前屏幕上的显示内容

    目录:[Swift]Xcode实际操作 本文将演示如何截取屏幕画面,并将截取图片,存入系统相册. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UI ...

  3. __setitem__,__getitem,__delitem__

    目录 __setitem__ __getitem__ __delitem__与__delattr__ class Foo: def __init__(self, name): self.name = ...

  4. LeetCode.905-按奇偶排序数组(Sort Array By Parity)

    这是悦乐书的第347次更新,第371篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第212题(顺位题号是905).给定一个非负整数数组A,返回一个由A的所有偶数元素组成的 ...

  5. mysql 配置大小写敏感后不能重启

    [问题现象] 在mysql的配置文件my.cnf配置lower_case_table_names=1后不能重启mysql,提示mysql.serviceJob for mysql.service fa ...

  6. JS时间框架之舍弃Moment.js拥抱Day.js

    什么是Day.js Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持完全一样. 如果您曾经用过 Moment.js, 那么您已经知道如 ...

  7. SpringBoot | SpringBoot启动错误

    Error starting ApplicationContext. To display the conditions report re-run your application with 'de ...

  8. SpringBoot | 查看默认版本配置

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...

  9. python 操作mysql数据库存

    代码: 说明:由于我本机没有安装数据库,数据库是在远程访问的,故地址不是localhost # __author__ = 'STEVEN' import pymysql host = '10.1.1. ...

  10. HDU-2182-Frog

    链接:https://vjudge.net/problem/HDU-2182 题意: 有一只青蛙,有n个节点,开始时在1节点,有k次往右跳的机会,每次跳的距离是a-b之间. 每个节点有一个值,到达那个 ...