Code in Go file:
package main
/*
#include <stdio.h>
int datspecialnumber() {
return 2015;
}
*/
import "C"
import "fmt"
func main() {
fmt.Println(C.datspecialnumber())
}
Output from go run test.go
:
# command-line-arguments
could not determine kind of name for C.datspecialnumber
More info
go version go1.4 linux/amd64
gcc (GCC) 4.9.2 20141224 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/president/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
Anyone have an idea of what is causing this error? Am i doing something wrong?
Remove the blank line above the import "C"
line.
As @alicebob said, there should be no newline between the /* ... */
cgo block and import "C"
Oops, my bad. Thanks for clearing that up, guys.
Wow! I met the same problem.
The f**k! Thanks guys, was stuck for hours, it was driving me mad...
I love conventions but sometimes it's kind of harsh!
I just want to add that multiline imports like
import (
"C"
"fmt"
)
Also breaks this stuff
Yeah the space might be the problem. But I still get this error when I'm trying to declare a c struct in cgo with no space between comments and import "C"
~~~go
type record C.some_struct
// could not determine kind of name for C.some_struct
~~~
this time it really can not determine
Most helpful comment
Remove the blank line above the
import "C"
line.