douxian1892 2015-04-03 19:50
浏览 64
已采纳

包含文件中的CGO未定义参考

Wraping up OpenJtalk in Go, files are successfully included and types are referenced without an issue, but functions trigger an undefined reference error.

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() {

}

And the weird part is that those same functions are declared right after the types:

mecab.h

// line 1584
typedef struct _Mecab{
   char **feature;
   int size;
   mecab_t *mecab;
} Mecab;

BOOL Mecab_initialize(Mecab *m);

Project webpage: http://open-jtalk.sourceforge.net/

  • 写回答

1条回答 默认 最新

  • dtxs9017 2015-04-03 20:07
    关注

    You need to add cgo linker options (LDFLAGS) with the path to and the name of your library. e.g.

    // #cgo CFLAGS: -Iyour-include-path
    // #cgo LDFLAGS: -Lyour-library-path -lyour-library-name-minus-the-lib-part
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值