<p>Trying to write cross-platform top equivalent. On FreeBSD, to get information about swap, I need to use cgo.<br/>
It fails with error <code>could not determine kind of name for C.kvm_swap</code></p>
<p>abridged example code </p>
<pre><code>// +build freebsd darwin
package main
// #include <kvm.h>
import "C"
var kd *C.kvm_t
var swapary *C.kvm_swap
</code></pre>
<p>go env</p>
<pre><code>GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOOS="freebsd"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/freebsd_amd64"
GO15VENDOREXPERIMENT=""
CC="cc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
</code></pre>
<p>Anyone can suggest any solution?
No, I can't go and use syscall.Sysctl - variables aren't in any of system information trees.</p>
<p>Note about kvm.h : <code>typedef struct __kvm kvm_t;</code> , but just <code>struct kvm_swap { ... }</code></p>
<hr/>**评论:**<br/><br/>postman_: <pre><p>Have you tried</p>
<p><code>
var swapary *C.struct_kvm_swap
</code></p>
<p>as it says in <a href="https://golang.org/cmd/cgo/">https://golang.org/cmd/cgo/</a> :</p>
<blockquote>
<p>To access a struct, union, or enum type directly, prefix it with struct<em>, union</em>, or enum_, as in C.struct_stat. </p>
</blockquote></pre>RandNho: <pre><p>Thank you, apparenly, I need to read, not to skim.</p>
<p>Also, it demanded ldflags next, but that problem was easier to solve.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传