I am trying to learn Cgo, so i tried accessing aerospike client from Cgo
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
}
But i get below errors. ( Please note the C program runs successfully when i do make and make run ).
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':
....
So i believe the issue is with the configuration in Makefile. I have searched for entire day and tried many solutions but invain. Can you help me how i could import Makefile in Cgo? Or an alternative to help me execute this successfully..
You need to link with the relevant library. I believe the library is called -laerospike
. In this case, the cgo
directive would look like this:
// #cgo LDFLAGS: -laerospike
Furthermore, you need to link in the relevant example code. I don't see a put
example in the official repository. You will likely have to copy part of its sources directly in the cgo
section of your Go file because examples are usually not intended for direct linking.