登录
首页 >  Golang >  Go问答

通过 Cgo 访问 aerospike C 客户端时出错

来源:stackoverflow

时间:2024-03-31 19:33:35 157浏览 收藏

对于一个Golang开发者来说,牢固扎实的基础是十分重要的,golang学习网就来带大家一点点的掌握基础知识点。今天本篇文章带大家了解《通过 Cgo 访问 aerospike C 客户端时出错》,主要介绍了,希望对大家的知识积累有所帮助,快点收藏起来吧,否则需要时就找不到了!

问题内容

我正在尝试学习cgo,所以我尝试从cgo访问aerospike客户端

package main  
// #cgo cflags: -g -wall
// #include 
// #include 
// #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

参见 the cgo documentation

此外,您需要链接相关的示例代码。我在官方存储库中没有看到 put 示例。您可能必须直接将部分源代码复制到 go 文件的 cgo 部分,因为示例通常不用于直接链接。

到这里,我们也就讲完了《通过 Cgo 访问 aerospike C 客户端时出错》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>