We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
一开始使用 GOOS=linux GOARCH='mipsle' go build main.go 编译出来的报错:
GOOS=linux GOARCH='mipsle' go build main.go
Illegal instruction
然后找啊找找到了要重新编译内核的时候开启 fpu 之类的, 这可麻烦了, 我压根不懂交叉编译,只能放弃了这种方式, 不过还有一种方法是使用 gomini/go-mips32 进行编译, 不过也是挺麻烦的.
最后找到了这里: golang/go#27236 , 加了一个环境变量就解决了我的问题
GOMIPS=softfloat GOOS=linux GOARCH='mipsle' go build main.go
The text was updated successfully, but these errors were encountered:
go 跨平台编译真的太舒服了
Sorry, something went wrong.
使用 build 参数 -ldflags “-s -w” 可以减少约 0.5M 体积哦~ 来自这里: https://blog.lutty.me/code/2017-04/golang-cross-compile-openwrt-ddwrt-build.html 虽然不知道什么原理但是能少点大小挺好的 原理在这: https://www.golangnote.com/topic/66.html
-s 去掉符号表(这样panic时,stack trace就没有任何文件名/行号信息了,这等价于普通C/C+=程序被strip的效果) -w 去掉DWARF调试信息,得到的程序就不能用gdb调试了
加上 CGO_ENABLED=0 就可以编译出 openwrt-x86 可以运行的可执行文件了
CGO_ENABLED=0
这是我用来编译 v2ray 的命令, 没加 CGO_ENABLED=0 之前也是出现 -ash: ./v2ray: not found 的错误, 加上就好了
-ash: ./v2ray: not found
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o v2ray ./main
参考自该文的第一句话: https://xiazemin.github.io/MyBlog/golang/2019/11/24/libc.html
go build编译时,CGO_ENABLED=1的,自动添加了一些动态库链接,所以编译时吧CGO_ENABLED=0就OK了
No branches or pull requests
一开始使用
GOOS=linux GOARCH='mipsle' go build main.go
编译出来的报错:然后找啊找找到了要重新编译内核的时候开启 fpu 之类的, 这可麻烦了, 我压根不懂交叉编译,只能放弃了这种方式, 不过还有一种方法是使用 gomini/go-mips32 进行编译, 不过也是挺麻烦的.
最后找到了这里: golang/go#27236 , 加了一个环境变量就解决了我的问题
The text was updated successfully, but these errors were encountered: