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"
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?