2019-01-05 03:22
浏览 408


I am trying to use CGO to bundle C files with a Golang package. Following instructions here:

I am getting this error:

# main 
src/main/main.go:16:8: could not determine kind of name for 
src/main/main.go:23:10: could not determine kind of name for C.greet

here is the structure:

enter image description here

main.go just looks like:

package main

// #cgo CFLAGS: -g -Wall
// #include <stdlib.h>
// #include "genericc/greeter.h"

import "C"

import (

func main() {
    name := C.CString("Gopher")

    year :=

    ptr := C.malloc(C.sizeof_char * 1024)

    size := C.greet(name, year, (*C.char)(ptr))

    b := C.GoBytes(ptr, size)

and I run to build it:

#!/usr/bin/env bash

dir="$(cd `dirname "$0"` && pwd)"
export GOPATH="$dir"

cd "$dir"

export CGOFILES=main
go install main

but when I run the bash script I get that error.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题