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