gojieba icon indicating copy to clipboard operation
gojieba copied to clipboard

1.4.1版本交叉编译问题

Open lihaoqiang001 opened this issue 1 year ago • 5 comments

升级到 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++相关的东西,大佬们有办法避免这个问题吗?

lihaoqiang001 avatar Jul 30 '24 07:07 lihaoqiang001

有两种方法(M 芯片 Mac):

  1. 本地使用 filosottile/musl-cross/musl-cross 这种工具
  2. 本地使用 docker 镜像去交叉编译

两种方法都有点麻烦,能从 SDK 本身去规避这个问题不?

lihaoqiang001 avatar Jul 30 '24 07:07 lihaoqiang001

顶上去,辛苦作者瞅瞅哇

lihaoqiang001 avatar Jul 31 '24 07:07 lihaoqiang001

  1. 安装好 filosottile/musl-cross/musl-cross ,编译的命令很长,但是包的体积大了好多
  2. 使用docker 编译的镜像 Linux 机器上用不了,提示无法执行

lihaoqiang001 avatar Jul 31 '24 07:07 lihaoqiang001

因为用 go 的 dlv debug 很方便,所以需要经常在 Mac 本机交叉编译Linux 的二进制文件

lihaoqiang001 avatar Jul 31 '24 07:07 lihaoqiang001

1.4.3 修复了一个编译问题,你试试看 1.4.3 是否ok?

yanyiwu avatar Sep 07 '24 07:09 yanyiwu

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.

github-actions[bot] avatar Oct 09 '25 01:10 github-actions[bot]

mac M3芯片,v1.4.4还是报错。 undefined: gojieba.Jieba undefined: gojieba.NewJieba

ByteDanceLiuYang avatar Oct 11 '25 09:10 ByteDanceLiuYang

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

ByteDanceLiuYang avatar Oct 13 '25 12:10 ByteDanceLiuYang