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: could not determine kind of name for C.datspecialnumber #9733

Closed
ghost opened this issue Jan 29, 2015 · 7 comments
Closed

cmd/cgo: could not determine kind of name for C.datspecialnumber #9733

ghost opened this issue Jan 29, 2015 · 7 comments

Comments

@ghost
Copy link

ghost commented Jan 29, 2015

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?

@alicebob
Copy link
Contributor

Remove the blank line above the import "C" line.

@davecheney
Copy link
Contributor

As @alicebob said, there should be no newline between the /* ... */ cgo block and import "C"

http://golang.org/cmd/cgo/

@ghost
Copy link
Author

ghost commented Jan 30, 2015

Oops, my bad. Thanks for clearing that up, guys.

@mikioh mikioh changed the title could not determine kind of name for C.datspecialnumber cmd/cgo: could not determine kind of name for C.datspecialnumber Jan 30, 2015
@leomq
Copy link

leomq commented Aug 24, 2015

Wow! I met the same problem.

@ezwiebel
Copy link

ezwiebel commented Aug 1, 2016

The f**k! Thanks guys, was stuck for hours, it was driving me mad...
I love conventions but sometimes it's kind of harsh!

@stgleb
Copy link
Contributor

stgleb commented Aug 31, 2016

I just want to add that multiline imports like

import (
               "C"
                "fmt"
)

Also breaks this stuff

@xgz123
Copy link

xgz123 commented May 18, 2017

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"

type record C.some_struct

// could not determine kind of name for C.some_struct

this time it really can not determine

@golang golang locked and limited conversation to collaborators May 18, 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

7 participants