为了账号安全,请及时绑定邮箱和手机立即绑定

包含文件中的 CGO 未定义引用

包含文件中的 CGO 未定义引用

Go
拉风的咖菲猫 2021-09-27 16:44:46
在 Go 中结束 OpenJtalk,文件被成功包含并且类型被引用没有问题,但函数会触发undefined reference错误。jtalk.go:package main// #cgo CFLAGS: -I/home/vagrant/open_jtalk/njd [...etc]/*#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <math.h>// Main headers #include "mecab.h"#include "njd.h"#include "jpcommon.h"#include "HTS_engine.h"// Sub headers #include "text2mecab.h"#include "mecab2njd.h"#include "njd_set_pronunciation.h"#include "njd_set_digit.h"#include "njd_set_accent_phrase.h"#include "njd_set_accent_type.h"#include "njd_set_unvoiced_vowel.h"#include "njd_set_long_vowel.h"#include "njd2jpcommon.h"*/import "C"type Open_JTalk struct {   mecab C.Mecab           each of these struct references are fine   njd C.NJD    jpcommon C.JPCommon    engine C.HTS_Engine }func (open_jtalk *Open_JTalk) Open_JTalk_initialize() {   C.Mecab_initialize(&open_jtalk.mecab)             // when any function is called the error happens   C.NJD_initialize(&open_jtalk.njd)   C.JPCommon_initialize(&open_jtalk.jpcommon)   C.HTS_Engine_initialize(&open_jtalk.engine)}func main() {}奇怪的是,这些相同的函数是在类型之后声明的:mecab.h// line 1584typedef struct _Mecab{   char **feature;   int size;   mecab_t *mecab;} Mecab;BOOL Mecab_initialize(Mecab *m);项目网页:http : //open-jtalk.sourceforge.net/
查看完整描述

1 回答

?
四季花海

TA贡献1811条经验 获得超5个赞

您需要添加LDFLAGS带有库路径和名称的cgo 链接器选项 ( )。例如


// #cgo CFLAGS: -Iyour-include-path

// #cgo LDFLAGS: -Lyour-library-path -lyour-library-name-minus-the-lib-part


查看完整回答
反对 回复 2021-09-27
  • 1 回答
  • 0 关注
  • 263 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信