英文:
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 <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"
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论