Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: cgo package call C system function error #20816

Closed
dzhwinter opened this issue Jun 27, 2017 · 1 comment
Closed

cmd/cgo: cgo package call C system function error #20816

dzhwinter opened this issue Jun 27, 2017 · 1 comment

Comments

@dzhwinter
Copy link

throw an exception of

could not determine kind of name for C.memcpy

here is the source code to reproduce the bug

package main

/*
#include <string.h>
#include <stdlib.h>
*/

import "C"

import (
  "fmt"
  "unsafe"
)

func main() {
  record := (**C.uchar)(unsafe.Pointer(uintptr(0)))
  // var record **C.uchar
  buf := []byte{1, 2, 3}
  fmt.Println(buf)
  size := C.int(len(buf))
  *record = (*C.uchar)(C.malloc(C.size_t(len(buf))))
  fmt.Println(*record)
  C.memcpy(unsafe.Pointer(*record), unsafe.Pointer(&buf[0]), C.size_t(len(buf)))

}
go version go1.8.3 darwin/amd64
macos Sierra
10.12 (16A323)
@bradfitz
Copy link
Contributor

Remove the blank line between your import "C" and the comment preceding it.

See https://golang.org/pkg/cmd/cgo/

@mikioh mikioh changed the title [cgo] cgo package call C system function error cmd/cgo: cgo package call C system function error Aug 2, 2017
@golang golang locked and limited conversation to collaborators Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants