9.1 Go环境
- goproxy地址
阿里云
https://mirrors.aliyun.com/goproxy/
七牛云
https://goproxy.cn/
开源版
https://goproxy.io/
nexus社区
https://gonexus.dev/
- 启用 Go Modules 功能
go env -w GO111MODULE=on
- 配置 GOPROXY 环境变量,以下三选一
- 七牛 CDN
go env -w GOPROXY=https://goproxy.cn,direct
- 阿里云
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
- 官方
go env -w GOPROXY=https://goproxy.io,direct
- nexus社区
go env -w GOPROXY=https://gonexus.dev/,direct
确认一下
$ go env | grep GOPROXY
GOPROXY="https://goproxy.cn"
- PowerShell
启用 Go Modules 功能
$env:GO111MODULE="on"
配置 GOPROXY 环境变量,以下三选一
- 七牛 CDN
$env:GOPROXY="https://goproxy.cn,direct"
- 阿里云
$env:GOPROXY="https://mirrors.aliyun.com/goproxy/,direct"
- 官方
$env:GOPROXY="https://goproxy.io,direct"
- Go 1.13及以上(推荐) 打开你的终端并执行
go env -w GO111MODULE=on
go env -w GOPATH=/home/users/go
go env -w GOPROXY=https://goproxy.io/,direct
- MacOS 或Linux 打开你的终端并执行
export GO111MODULE=on
export GOPROXY=https://goproxy.io/
export GOPATH=/Users/{user}/go
- or
echo "export GO111MODULE=on" >> ~/.profile
echo "export GOPROXY=https://goproxy.io/" >> ~/.profile
source ~/.profile
- Windows PowerShell 打开你的 PowerShell 并执行
$env:GO111MODULE = "on"
$env:GOPROXY = "https://goproxy.io/"
$env:GOPATH = "c:\Users\Administrator\go"
- Windows Cmd
# Enable the go modules feature
set GO111MODULE=on
# Set the GOPROXY environment variable
set GOPROXY=https://goproxy.io/
- go编译文件过大优化
- 编译优化
go build -ldflags="-w -s"
- upx压缩(容易误杀)
upx -9 main.exe
Go编译-race参数实现VT全免杀
https://www.modb.pro/db/88394
- shellcode地址
https://golangrepo.com/tag/shellcode-convert
- race竞争条件生成利于免杀
go build -ldflags "-s -w" -race main.go -o main.exe
- -H=windowsgui(改参数容易被查杀)
go build -ldflags "-s -w -H=windowsgui" -o main.exe -race main.go
- go编译dll
go build -ldflags="-w -s" -buildmode=c-shared -o main.dll main.go
- garble安装
go install mvdan.cc/garble@latest
- garble编译
garble -tiny build -ldflags "-s -w"
- go build 命令参数详解
-a
完全编译,不理会-i产生的.a文件(文件会比不带-a的编译出来要大?)
-n
仅打印输出build需要的命令,不执行build动作(少用)。
-p n
开多少核cpu来并行编译,默认为本机CPU核数(少用)。
-race
同时检测数据竞争状态,只支持 linux/amd64, freebsd/amd64, darwin/amd64 和 windows/amd64.
-msan
启用与内存消毒器的互操作。仅支持linux / amd64,并且只用Clang / LLVM作为主机C编译器(少用)。
-v
打印出被编译的包名(少用).
-work
打印临时工作目录的名称,并在退出时不删除它(少用)。
-x
同时打印输出执行的命令名(-n)(少用).
-asmflags 'flag list'
传递每个go工具asm调用的参数(少用)
-buildmode mode
编译模式(少用)
'go help buildmode'
-compiler name
使用的编译器 == runtime.Compiler
(gccgo or gc)(少用).
-gccgoflags 'arg list'
gccgo 编译/链接器参数(少用)
-gcflags 'arg list'
垃圾回收参数(少用).
-installsuffix suffix
a suffix to use in the name of the package installation directory,
in order to keep output separate from default builds.
If using the -race flag, the install suffix is automatically set to race
or, if set explicitly, has _race appended to it. Likewise for the -msan
flag. Using a -buildmode option that requires non-default compile flags
has a similar effect.
-ldflags 'flag list'
'-s -w': 压缩编译后的体积
-s: 去掉符号表
-w: 去掉调试信息,不能gdb调试了
-linkshared
链接到以前使用创建的共享库
-buildmode=shared.
-pkgdir dir
从指定位置,而不是通常的位置安装和加载所有软件包。例如,当使用非标准配置构建时,使用-pkgdir将生成的包保留在单独的位置。
-tags 'tag list'
构建出带tag的版本.
-toolexec 'cmd args'
a program to use to invoke toolchain programs like vet and asm.
For example, instead of running asm, the go command will run
'cmd args /path/to/asm <arguments for asm>'.
9.2 Nim环境
nim c -d:release -r test.nim
nim objc test.nim
nim js test.nim
伪交叉编译: 伪交叉编译会在nimcache目录里生成跨平台c语言代码, 当前目录生成compile_test.sh编译脚本, 把几个文件都考到要生成的i386:linux机器上运行该sh脚本就会编译成应用程序.
nim c --cpu:i386 --os:linux --compile_only --gen_script test.nim
交叉编译:
nim c --cpu:arm --os:linux test.nim
当然你得设置编译器和链接器这些玩意, 同目录建一个nim.cfg文件里面写上相关参数.
arm.linux.gcc.path = "/usr/bin"
arm.linux.gcc.exe = "arm-linux-gcc"
arm.linux.gcc.linkerexe = "arm-linux-gcc"
这里有一个编译emscripten fc nes模拟器程序例子(具体可看这里nimnes), 先在nim.cfg设置好参数, 然后运行
nim -d:release -d:emscripten
编译
nim c -d:release --opt:size Caesar.nim
nim c -d=mingw -d:release --app=console Nimloader.nim
9.3 Rust环境
- rust安装
curl https://sh.rustup.rs -sSf | sh
sudo apt-get install musl-tools
- Cargo创建新项目
cargo new hello-rust
- Cargo编译
rustc hello_world.rs
- 编译默认debug版本
cargo build
- cargo编译release版本
cargo build --release
- cargo编译debug版本
cargo build --debug
cargo run // 运行
- 多平台交叉编译
rustup install stable-x86_64-unknown-linux-gnu
rustup target add x86_64-unknown-linux-gnu
cargo build --release --target x86_64-unknown-linux-gnu
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl
rustup target list
- 添加或移除平台
添加
rustup target add aarch64-unknown-linux-gnu
移除
rustup target remove aarch64-unknown-linux-gnu
- 更新模块
cargo update -p time
- 交叉编译器并配置
`要发布到linux-arm64平台,可以在 https://releases.linaro.org/components/toolchain/binaries/ 这里下载编译器,推荐latest版本。或者从 https://github.com/kekeqy/windows-hosted-aarch64-linux-musl-gcc-cross-compiler 这里下载。
要发布到linux-x64平台,可以在 https://github.com/kekeqy/windows-hosted-x86_64-linux-musl-gcc-cross-compiler 这里下载编译器,亲测可用。 尽量选择 musl 版本,而非gnu版本因为musl是静态编译,不依赖系统本地的库文件。下载好的编译器解压出来,并将bin目录添加到系统环境变量Path中。`
C:\Users\Administrator\.cargo\config.toml
/root/.cargo/config.toml
[target.aarch64-unknown-linux-gnu]
linker = “aarch64-linux-gnu-gcc”
[target.x86_64-unknown-linux-musl]
linker = “x86_64-linux-musl-gcc”
9.4 PythonCode环境
- Linux更换pip源
python2.7
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python3.6
wget https://bootstrap.pypa.io/pip/3.6/get-pip.py
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
mkdir ~/.pip
cat << EOF >> ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn break-system-packages = true EOF
- Centos安装python3.8
yum install zlib zlib-devel bzip2-devel ncurses-devel sqlite-devel readline-devel libffi libffi-devel openssl-devel tk-devel gcc gcc-c++ make -y
wget https://www.python.org/ftp/python/3.8.19/Python-3.8.19.tgz --no-check-certificate
tar xvf Python-3.8.19.tgz
cd Python-3.8.19
./configure --enable-shared
make&&make install
find /usr/local -name libpython*.1.0 -exec cp {} /usr/lib/ \; -exec cp {} /usr/lib64/ \;
- pyinstaller编译exe
yum install libffi-devel -y
pip3 install --upgrade pip setuptools wheel
pip3 install pyinstaller
- gcc升级
yum install centos-release-scl /y
yum install devtoolset-8-gcc devtoolset-8-gcc-c++ /y
echo "source /opt/rh/devtoolset-8/enable" >>~/.bashrc
pyinstaller -F -i favicon.ico demo.py
- nuitka编译exe
yum install ccache patchelf python3-devel /y
pip3 install zstandard -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install orderedset -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install nuitka -i https://pypi.tuna.tsinghua.edu.cn/simple
nuitka --standalone --onefile --remove-output --mingw64 demo.py
暂无评论内容