Closed davecb closed 1 day ago
Related Issues
Related Discussions
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
If you write a C program (with a modern compiler at least) and call an undeclared function, you don't get to the linker. You get an error about the function name not being known. That's what is happening here. I understand being confused when you wrote C.Cstring and thought you'd written C.CString, but the error is accurate: maybe there really is a library providing Cstring, and if so cgo can't find it. The same error happens if you do C.asdf or any other misspelling of any function name. I'm not sure what we can change here.
I think we can be clearer than "could not determine kind of name". I'll send a CL.
Change https://go.dev/cl/630375 mentions this issue: cmd/cgo: improve error message for unknown name
Go version
go version go1.23.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I made a spelling mistake, and tried to link to a CGO function that didn't exist, "C.Cstring". To my surprise I got
./minimum_code.go:15:13: could not determine kind of name for C.Cstring
That has me looking in all the wrong places!When, after a nice cup of tea, I spotted the typo, and got a far better error,
/tmp/go-build/minimum_code.cgo2.c:51:(.text+0x8): undefined reference to PDQ_Init
I had been thinking that calling the misspelled function would get me an undefined-reference error, which is more normal.
If this is something that can be fixed, I'd recommend it: Mr Google found lots and lots of discussion of
could not determine kind of name for C.Cstring
, none relevant. Even a better error message would suffice.If there really is a Cstring function that you want to keep, bug me about controlling its visibility: Paul Stachour and I have written in the Communications of the ACM about that problem (;-))
What did you see happen?
When misspelled, I got ./minimum_code.go:15:13: could not determine kind of name for C.Cstring
when fixed, I got /tmp/go-build/minimum_code.cgo2.c:51:(.text+0x8): undefined reference to `PDQ_Init'
I'm surprised I didn't get a linkage error for a missing C.Cstring()
What did you expect to see?
./minimum_code.go:15:13: undefined reference to Cstring