gojieba
gojieba copied to clipboard
1.4.1版本交叉编译问题
升级到 1.4.1 版本,这个问题没有了: In file included from jieba.cpp:5: In file included from ../../../pkg/mod/github.com/yanyiwu/[email protected]/deps/cppjieba/Jieba.hpp:4: In file included from ../../../pkg/mod/github.com/yanyiwu/[email protected]/deps/cppjieba/QuerySegment.hpp:8: ../../../pkg/mod/github.com/yanyiwu/[email protected]/deps/cppjieba/DictTrie.hpp:152:12: warning: variable 'lineno' set but not used [-Wunused-but-set-variable] ../../../pkg/mod/github.com/yanyiwu/[email protected]/deps/cppjieba/DictTrie.hpp:217:17: warning: variable 'lineno' set but not used [-Wunused-but-set-variable]
但是交叉编译还是不行:GOOS=linux GOARCH=amd64 go build -gcflags=all='-N -l' -o my-app,报错: undefined: gojieba.Jieba undefined: gojieba.NewJieba
看了下里面用了C/C++相关的东西,大佬们有办法避免这个问题吗?
有两种方法(M 芯片 Mac):
- 本地使用 filosottile/musl-cross/musl-cross 这种工具
- 本地使用 docker 镜像去交叉编译
两种方法都有点麻烦,能从 SDK 本身去规避这个问题不?
顶上去,辛苦作者瞅瞅哇
- 安装好 filosottile/musl-cross/musl-cross ,编译的命令很长,但是包的体积大了好多
- 使用docker 编译的镜像 Linux 机器上用不了,提示无法执行
因为用 go 的 dlv debug 很方便,所以需要经常在 Mac 本机交叉编译Linux 的二进制文件
1.4.3 修复了一个编译问题,你试试看 1.4.3 是否ok?
This issue has not been updated for over 1 year and will be marked as stale. If the issue still exists, please comment or update the issue, otherwise it will be closed after 7 days.
mac M3芯片,v1.4.4还是报错。 undefined: gojieba.Jieba undefined: gojieba.NewJieba
v1.4.4解决方案:
- 1.安装macos-cross-toolchains。参考https://github.com/messense/homebrew-macos-cross-toolchains
- 2.在mac上执行交叉编译:
CXX=x86_64-linux-gnu-g++ CC=x86_64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags -extldflags '-static' -o xxx