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.CStirng #31390

Closed
nitishsaboo opened this issue Apr 10, 2019 · 7 comments
Closed

cmd/cgo: could not determine kind of name for C.CStirng #31390

nitishsaboo opened this issue Apr 10, 2019 · 7 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@nitishsaboo
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.12.1 darwin/amd64

Does this issue reproduce with the latest release?

Not Sure

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN="/Users/nitish.saboo/Documents/goworkspace/bin"
GOCACHE="/Users/nitish.saboo/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nitish.saboo/Documents/goworkspace/"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I am building the go code that is binded with the C code.

pacage main

// #include "stdlib.h"
import "C"
import (
"fmt"
_ "fmt"
"regexp"
"strconv"
"unsafe"
)

func process(program string, message string) {

app := C.CString(program)
defer C.free(unsafe.Pointer(app))
msg := C.CString(message)
defer C.free(unsafe.Pointer(msg))

}

What did you expect to see?

I thought the code would build successfully

What did you see instead?

$ go build main.go

command-line-arguments

./main.go:136:16: could not determine kind of name for C.CStirng
./main.go:87:20: could not determine kind of name for C.String

@ianlancetaylor ianlancetaylor changed the title cgo:could not determine kind of name for C.CStirng cmd/cgo: could not determine kind of name for C.CStirng Apr 10, 2019
@ianlancetaylor
Copy link
Contributor

I can't recreate the problem. There are typos in your sample code; for example, you wrote pacage rather than package. In your error messages, there are also typos. Neither name is correct. The function is C.CString, not C.Cstirng or C.String. Can you show us the exact program that you are building, and the exact error messages you see? Cut and paste from your terminal, don't retype. Thanks.

@nitishsaboo
Copy link
Author

I can't recreate the problem. There are typos in your sample code; for example, you wrote pacage rather than package. In your error messages, there are also typos. Neither name is correct. The function is C.CString, not C.Cstirng or C.String. Can you show us the exact program that you are building, and the exact error messages you see? Cut and paste from your terminal, don't retype. Thanks.

Hi Ian,

Apologies for typo.A small excerpt from the code.

package main

// #include "abc/abc-xyz.h"
import "C"
import (
	"fmt"
_ "fmt"
"unsafe"
)

func proc(envelope Envelope) {
	a := envelope.pgm
	b := envelope.msg
	if a == " " || b == " " {
	fmt.Println("Must provide a and b")
}
	a1 := C.CString(a)
	defer C.free(unsafe.Pointer(a1))
	b1 := C.CString(b)
	defer C.free(unsafe.Pointer(b1))
	C.match(a1, C.int(len(a1)), b1, C.int(len(b1)))

}
type Envelope struct {

pgm string
msg string

}

I am trying to load an external library.The header file points to the match function.When I run 'go build main.go' it shows the following issue:

could not determine kind of name for C.CStirng
could not determine kind of name for C.String

All the C dependencies reside in the abc folder.Do I need to zip the dependencies ?

$ go env
GOARCH="amd64"
GOBIN="/Users/nitish.saboo/Documents/goworkspace/bin"
GOCACHE="/Users/nitish.saboo/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nitish.saboo/Documents/goworkspace/"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3n/gnx8m6wx6zndptdxj3z3n61mfnyqn2/T/go-build470713600=/tmp/go-build -gno-record-gcc-switches -fno-common"

@bcmills
Copy link
Contributor

bcmills commented Apr 10, 2019

@nitishsaboo please attach (or link to) a complete source file that exhibits the problem, not just an excerpt. If there is a bug here, we need to be able to reproduce it in order to determine when we have fixed it.

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 10, 2019
@ianlancetaylor
Copy link
Contributor

If the error messages quoted above are exactly what you see, then the bug is that your code has typos for C.CString.

@nitishsaboo
Copy link
Author

Thanks Ian.Issue resolved

@xiaokai111
Copy link

how to fix it? pleae teach me

@nitishsaboo
Copy link
Author

nitishsaboo commented Mar 3, 2020

@xiaokai111 there was a typo that resolved the issue.

@golang golang locked and limited conversation to collaborators Mar 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants