我搞了个小项目,用的是 goreleaser 来编译各环境应用,由于需要用到 sqlite 便在配置文件中把CGO_ENABLED
的值设置为 1 ,但是在编译过程中遇到各种各样的问题。
build failed after 10s error=failed to build for darwin_arm64: exit status 1: # runtime/cgo cgo: C compiler "clang" not found: exec: "clang": executable file not found in %PATH% ----------- build failed after 11s error=failed to build for linux_arm_6: exit status 1: # runtime/cgo gcc: error: unrecognized command line option '-marm'; did you mean '-mabm'? ---------- failed to build for linux_amd64_v1: exit status 1: # runtime/cgo arm-linux-gnueabi-gcc: error: unrecognized command-line option '-m64'
我觉得我已经脑掺了
![]() | 1 ysc3839 2024-09-16 22:24:08 +08:00 via Android 不是写了 clang 吗? 要不然去 LLVM 官网下,要不然用 MSYS2 里面的 clang 。 |
![]() | 2 kuxiaobai OP @ysc3839 我已经在此 https://releases.llvm.org/ 下载并安装了,也设置了环境变量,之后就这样: ``` build failed after 11s error=failed to build for linux_arm_6: exit status 1: # runtime/cgo gcc: error: unrecognized command line option '-marm'; did you mean '-mabm'? ``` |
4 0o0O0o0O0o 2024-09-16 22:42:46 +08:00 via iPhone 既然你用 goreleaser ,那就用它的容器 docker run --rm -v /source:/app -w /app goreleaser/goreleaser --verbose release --snapshot --clean --skip=announce,publish,validate |
![]() | 5 TaurusXin 2024-09-16 23:06:22 +08:00 via iPhone sqlite 不是有库吗为什么要用 c 版的 |
![]() | 7 monkeyWie 2024-09-17 00:05:05 +08:00 下载 zig ,然后有个 zig 的交叉编译工具链好像可以 |
![]() | 8 body007 2024-09-17 08:44:44 +08:00 这是以前弄得交叉编译 docker 制作方法。 https://github.com/jan-bar/xgo/blob/master/docker/readme.md 这里有个在 Linux 的 docker 交叉编译 window 的 sqlite 脚本,不过当时没有研究交叉编译 arm 的方法。但我感觉就是安装 arm64-gcc 的编译工具,然后给 go 设置环境变量即可。 https://github.com/jan-bar/xgo/blob/master/tests/sqlite/build.sh 还有这个纯 go 的 sqlite 驱动可以试试看: https://gitlab.com/cznic/sqlite |
![]() | 9 kuxiaobai OP @0o0O0o0O0o 感谢老哥,我也试过用 docker 但编译 arm 还是会遇到问题 |
![]() | 10 kuxiaobai OP @body007 感谢 老哥,amd 的没得问题,就是在 arm 编译上遇到了问题,sqlite 的驱动我用 https://github.com/glebarez/sqlite |
![]() | 11 flyqie 2024-09-17 15:55:47 +08:00 via Android ![]() 说真的,这种需求建议上专门的 cicd 环境搞,cgo 的交叉编译真的不太好做,除了 android 这种以外,剩下都建议在目标系统上做。 |
![]() | 12 Kisesy 2024-09-17 18:54:58 +08:00 sqlite3 库换成 https://github.com/ncruces/go-sqlite3, 不用 C |
![]() | 13 jim9606 2024-09-17 19:55:31 +08:00 via Android 小项目别折腾了吧,找纯 go 实现的 sqlite 客户端库。 |
14 intersect 2024-09-17 20:09:37 +08:00 sqlite 使用 github.com/mattn/go-sqlite3 ,Window11+WSL 下编译起来还算方便 编译参数参考: export CGO_ENABLED=1 # AMD64 #export GOOS=linux #export GOARCH=amd64 export GOOS=linux # arm #export GOARCH=arm #export CC=arm-linux-gnueabihf-gcc # aarch64 # apt-get install -y aarch64-linux-gnu-gcc export GOARCH=arm64 export CC=aarch64-linux-gnu-gcc |
15 xsen 2024-09-18 16:43:04 +08:00 sqlite 有 pure-go 版本的, https://github.com/glebarez/go-sqlite.git |