我正在尝试学习 Cgo,所以我尝试从 Cgo 访问 aerospike 客户端
package main
// #cgo CFLAGS: -g -Wall
// #include <stdlib.h>
// #include <string.h>
// #include "aerospike-client-c/examples/put/example_utils.h"
import "C"
import (
"unsafe"
)
func main() {
retvals := C.putitnew()
_=retvals
}
但我遇到以下错误。 (请注意,当我执行 make 和 make run 时,C 程序运行成功)。
undefined reference to `example_get_opts'
./aerospike-client-c/examples/put/example.c:66: undefined reference to
`example_connect_to_aerospike'
./aerospike-client-c/examples/put/example.c:69: undefined reference to
`example_remove_test_record'
./aerospike-client-c/examples/put/example.c:78: undefined reference to
`as_record_init'
./aerospike-client-c/examples/put/example.c:79: undefined reference to
`as_record_set_int64'
/tmp/go-build283334635/b046/_x002.o: In function `as_record_set_str':
....
所以我认为问题在于 Makefile 中的配置。我已经搜索了一整天并尝试了许多解决方案但无济于事。你能帮我如何在 Cgo 中导入 Makefile 吗?或者帮助我成功执行此操作的替代方法..
最佳答案
您需要链接到相关的图书馆。我相信这个库叫做 -laerospike
。在这种情况下,cgo
指令将如下所示:
// #cgo LDFLAGS: -laerospike
此外,您需要链接相关的示例代码。我在官方存储库中没有看到 put
示例。您可能必须直接在 Go 文件的 cgo
部分复制其部分源代码,因为示例通常不用于直接链接。
关于c - 通过Cgo访问aerospike C客户端报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52698861/