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

huangapple go评论77阅读模式
英文:

Unable to include required C header files for go program

问题

我正在尝试在我的Go程序中包含一个位于/usr/local/WordNet-3.0/include/目录下的头文件。

使用以下标志:

// #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\n\n%s", dblicense, license);
}
*/
import "C"
import "unsafe"
import (
        "os"
)

但是当我使用go run运行程序时,出现以下错误:

"fatal error: 'wn.h'文件未找到。"我使用的是go 1.5.1。

如果能告诉我我做错了什么,将不胜感激。

编辑:我已经通过将文件复制到我的工作目录中使其正常工作,但我仍然想知道我之前做错了什么。

英文:

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\n\n%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

得分: 5

在本地进行了快速测试:你需要删除 cgo 标志和 C 代码之间的空行。

尝试这样做:

// #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\n\n%s", dblicense, license);
}
*/
import "C"
import "unsafe"
import (
        "os"
)
英文:

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 &lt;stdio.h&gt;
 #include &lt;stdlib.h&gt;
 #include &lt;string.h&gt;
 #include &quot;wn.h&quot;

static void printlicense() {
    printf(&quot;WordNet License %s\n\n%s&quot;, dblicense, license);
}
*/
import &quot;C&quot;
import &quot;unsafe&quot;
import (
        &quot;os&quot;
)

huangapple
  • 本文由 发表于 2015年10月4日 19:42:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/32933060.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定