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: _GoString_ is unavailable #24097

Closed
LionNatsu opened this issue Feb 24, 2018 · 2 comments
Closed

cmd/cgo: _GoString_ is unavailable #24097

LionNatsu opened this issue Feb 24, 2018 · 2 comments

Comments

@LionNatsu
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.4 linux/amd64

Does this issue reproduce with the latest release?

I don't know.

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/lion/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build491035465=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
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?

package main

/*
#include <stdio.h>
void do_something(_GoString_ go_string) {
    return;
}
*/
import "C"

func main() {
	C.do_something("example")
}

What did you expect to see?

Go compiles it successfully.

What did you see instead?

....go:12:2: could not determine kind of name for C.do_something

gcc errors for preamble:
....go:5:19: error: unknown type name '_GoString_'
 void do_something(_GoString_ go_string) {
                   ^~~~~~~~~~

Documentation

https://golang.org/cmd/cgo/#hdr-Go_references_to_C

A C function may be declared in the Go file with a parameter type of the special name _GoString_. This function may be called with an ordinary Go string value. The string length, and a pointer to the string contents, may be accessed by calling the C functions

size_t _GoStringLen(_GoString_ s);
const char *_GoStringPtr(_GoString_ s);

These functions are only available in the preamble, not in other C files. The C code must not modify the contents of the pointer returned by _GoStringPtr. Note that the string contents may not have a trailing NUL byte.

@crvv
Copy link
Contributor

crvv commented Feb 24, 2018

It is a new feature added in Go 1.10.

https://golang.org/doc/go1.10#cgo

@LionNatsu
Copy link
Contributor Author

@crvv Thank you...

@golang golang locked and limited conversation to collaborators Feb 24, 2019
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

4 participants