go test
进行测试。In file included from gofst.cpp:2:
In file included from /usr/local/include/fst/fstlib.h:28:
In file included from /usr/local/include/fst/expanded-fst.h:13:
In file included from /usr/local/include/fst/log.h:26:
/usr/local/include/fst/flags.h:143:50: error: a space is required between consecutive right angle brackets (use '> >')
/usr/local/include/fst/flags.h:174:37: error: a space is required between consecutive right angle brackets (use '> >')
export CGO_CFLAGS="-g -O2 -std=c++11 -stdlib=libc++"
来使用C ++ 11,但我得到了这个。error: invalid argument '-std=c++11' not allowed with 'C/ObjC'
FAIL _/Users/chaoyang/Learn/go/cgo/gofst [build failed]
Belows是所有文件
gofst.h
//gofst.h
#ifndef GO_FST_H
#define GO_FST_H
#ifdef __cplusplus
extern "C" {
#endif
typedef void* Fst;
Fst FstInit(void);
void FstFree(Fst f);
void AddState(Fst f);
void SetStart(Fst f, int startState);
#ifdef __cplusplus
}
#endif
#endif
gofst.cpp
//gofst.cpp
#include <fst/fstlib.h>
#include "gofst.h"
Fst FstInit()
{
StdVectorFst fst = new StdVectorFst();
return (void*)fst;
}
void FstFree(Fst f)
{
StdVectorFst * fst = (StdVectorFst*)f;
delete fst;
}
void AddState(Fst f)
{
StdVectorFst * fst = (StdVectorFst*)f;
f->AddState();
}
void SetStart(Fst f, int startState)
{
StdVectorFst * fst = (StdVectorFst*)f;
f->SetStart(startState);
}
gofst.go
// gofst.go
package gofst
// #include "gofst.h"
import "C"
//Fst structy
type Fst struct {
fst C.Fst
}
//New create a new Fst object
func New() Fst {
var ret Fst
ret.fst = C.FstInit()
return ret
}
//Free free the fst object
func (f Fst) Free() {
C.FstFree(f.fst)
}
//AddState add a new state for fst
func (f Fst) AddState() {
C.AddState(f.fst)
}
//SetStart set a new id for start state
func (f Fst) SetStart(state int) {
C.SetStart(f.fst, state)
}
gofst_test.go
// gofst_test.go
package gofst
import "testing"
func TestFfst(t *testing.T) {
fst := New()
fst.AddState()
fst.SetStart(0)
foo.Free()
}
谢谢!