如何让Go找到库的头文件?

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

How to let Go find library headers?

问题

我已经搜索了一段时间,但找不到解决这个问题的方法。

因为像SDL2这样的库不是OpenBSD操作系统的一部分,它们存储在/usr/local目录下。Go似乎在/usr/include而不是/usr/local/include中查找头文件。我在go env中看到了一些标志,但我无法编辑它们。

有没有一种方法可以解决这个问题而不使用符号链接?也许Go中有类似于C编译器中常见的-I标志的等效方法?

英文:

I've been searching for a while but cannot find a solution to this issue.

Because libraries like SDL2 are not part of the OpenBSD operating system, they are stored in /usr/local. Go seems to be looking for headers in /usr/include and not /usr/local/include. I see flags in go env but I'm unable to edit them.

Is there a way to resolve this issue without symlinks? Perhaps a Go equivalent of the -I flag common in C compilers?

答案1

得分: 3

如果你正在使用Cgo,你必须使用类似这样的代码:

/*
#cgo CFLAGS: -I/usr/local/ssl/include
#cgo LDFLAGS: -lcrypto -L/usr/local/ssl/lib
*/
import "C"

在这个例子中,我是用它来编译最新的OpenSSL。根据你的需求进行编辑。

英文:

If you're using Cgo, you must use something like this:

/*
#cgo CFLAGS: -I/usr/local/ssl/include
#cgo LDFLAGS: -lcrypto -L/usr/local/ssl/lib
*/
import "C"

In this case I'm using it to compile against the latest OpenSSL. Edit to suit your needs.

huangapple
  • 本文由 发表于 2017年5月22日 08:07:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/44102971.html
匿名

发表评论

匿名网友

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

确定