Skip to content
New issue

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

windows 7 64位,测试gojieba 的bleve示例代码,undefined: gojieba.Jieba #18

Closed
kerneltravel opened this issue Jan 13, 2017 · 1 comment

Comments

@kerneltravel
Copy link

kerneltravel commented Jan 13, 2017

环境如题,go 1.7.3版本。

>go build blevemaintest.go
github.com\yanyiwu\gojieba\bleve\tokenizer.go:12: undefined: gojieba.Jieba
>cgo  blevemain.go
cannot find import "C"

发现gojieba.Jieba 是在jieba.go 里面定义的c/c++语言的方式:

package gojieba

/*
#cgo CXXFLAGS: -I./deps -DLOGGING_LEVEL=LL_WARNING -O3 -Wall
#include <stdlib.h>
#include "jieba.h"
*/
import "C"
import "unsafe"

type TokenizeMode int

const (
	DefaultMode TokenizeMode = iota
	SearchMode
)

type Word struct {
	Str   string
	Start int
	End   int
}

type Jieba struct {
	jieba C.Jieba
}

怎么处理cgo引起的undefined: gojieba.Jieba错误?

@kerneltravel
Copy link
Author

kerneltravel commented Jan 13, 2017

解决了。gojiebad的bleve测试代码,使用LiteIDE菜单内自带的go build都可以了。在这之前,需要做一下准备:
先git clone 出gojieba到GOROOT内,并在LiteIDE内对其做go build和go install。
LiteIDE环境必须设置有CGO_ENABLED=1
例如我的 ( LiteIDE 自动处理环境参数的 ):

set GOARCH=386
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=你的完整GOPATH路径内容
set GORACE=
set GOROOT=d:\install\go
set GOTOOLDIR=d:\install\go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\myname\AppData\Local\Temp\go-build198692226=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant