dpowhyh70416 2015-10-04 11:42
浏览 120
已采纳

无法包含go程序所需的C头文件

I am trying to include a header file which exists in /usr/local/WordNet-3.0/include/ in my go program

using these flags

// #cgo CFLAGS: -I/usr/local/WordNet-3.0/include
// #cgo LDFLAGS: /usr/local/WordNet-3.0/lib/libWN.3.dylib

/*
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "wn.h"

static void printlicense() {
    printf("WordNet License %s

%s", dblicense, license);
}
*/
import "C"
import "unsafe"
import (
        "os"
)

but when I run my program using go run, it gives me following error:

"fatal error: 'wn.h' file not found." I am on go 1.5.1.

Any help on what I am doing wrong would be appreciated.

EDIT : I have got this to work by copying the file over in my working directory, but I would still like to know, what I was doing wrong.

  • 写回答

1条回答 默认 最新

  • dongtao6842 2015-10-04 14:48
    关注

    Did a quick test on my local : you need to remove the blank line between your cgo flags and your C code.

    Try this :

    // #cgo CFLAGS: -I/usr/local/WordNet-3.0/include
    // #cgo LDFLAGS: /usr/local/WordNet-3.0/lib/libWN.3.dylib
    /*
     #include <stdio.h>
     #include <stdlib.h>
     #include <string.h>
     #include "wn.h"
    
    static void printlicense() {
        printf("WordNet License %s
    
    %s", dblicense, license);
    }
    */
    import "C"
    import "unsafe"
    import (
            "os"
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置