【问题标题】:How to point to C header files in GO?如何在 GO 中指向 C 头文件?
【发布时间】:2016-11-17 19:02:09
【问题描述】:

刚接触 GoLang,所以请放轻松。我安装了这个包,它是 HDF5s 文件系统的 GO 绑定:

go get github.com/sbinet/go-hdf5

我明白了

fatal error: hdf5.h: No such file or directory
// #include "hdf5.h"

文件 hdf5.h(来自原始 hdfs 库,而不是 go 包)位于

usr/include/hdf5s/series

如何告诉 go 编译器在 /user/include/hdf5s/series 目录中查找此头文件?

【问题讨论】:

  • 这可能是一个错字,但/usr != /user usr 代表通用系统资源。

标签: go include header-files hdf5


【解决方案1】:

使用CGO_CFLAGS 环境变量(documentation) 将-I 标志传递给C 编译器:

CGO_CFLAGS="-I/usr/include/hdf5s/series" go get -u github.com/sbinet/go-hdf5

【讨论】:

  • 这行得通,但现在我得到 # github.com/sbinet/go-hdf5 /usr/bin/ld: cannot find -lhdf5 /usr/bin/ld: cannot find -lhdf5_hl collect2: error : ld 返回 1 个退出状态“代码”
  • @BromQuinn:您可能需要添加库的路径:CGO_CFLAGS="-I/usr/include/hdf5s/series -L/usr/library path..." go get -u github.com/sbinet/go-hdf5
  • Golang 是否使用C_INCLUDE_PATHLIBRARY_PATH
  • @CMCDragonkai 确实如此
  • 可以使用 CGO_LDFLAGS 指定库的位置。
猜你喜欢
  • 1970-01-01
  • 2019-12-09
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
  • 1970-01-01
  • 2019-07-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多