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: _GoStringLen and _GoStringPtr implicitly declared when exporting Go function #71226

Closed
rittneje opened this issue Jan 10, 2025 · 3 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rittneje
Copy link
Contributor

Go version

go version go1.22.10 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE='auto'
GOARCH='amd64'
GOBIN=''
GOCACHE='/tmp/.gocache'
GOENV='/Users/rittneje/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/rittneje/test/pkg/mod'
GONOPROXY='[redacted]'
GONOSUMDB='[redacted]'
GOOS='darwin'
GOPATH='/Users/rittneje/test'
GOPRIVATE='[redacted]'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/rittneje/go1.22.10'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/Users/rittneje/go1.22.10/pkg/tool/darwin_amd64'
GOVCS='[redacted]'
GOVERSION='go1.22.10'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/rittneje/test/src/cgotest/go.mod'
GOWORK='/Users/rittneje/test/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/kf/kr7_s3xx0l12zbj3jrn082hmzy5gvy/T/go-build3787749113=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I am writing an application that uses cgo. For this reason, I want to compile with all warnings as errors.

Here is a minimal reproducer:

package main

/*
#cgo CFLAGS: -Werror -Wimplicit-function-declaration

void bar(_GoString_ str) {
	_GoStringLen(str);
	_GoStringPtr(str);
}
*/
import "C"

func main() {
}

//export foo
func foo() {
}

What did you see happen?

$ go build
# cgotest
In file included from _cgo_export.c:4:
main.go:7:2: error: call to undeclared function '_GoStringLen'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
main.go:8:2: error: call to undeclared function '_GoStringPtr'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

Without the //export foo directive, it compiles without issue.

What did you expect to see?

No errors.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 10, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Jan 10, 2025
@prattmic
Copy link
Member

cc @golang/compiler

@prattmic prattmic added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 10, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/642235 mentions this issue: cmd/cgo: declare _GoString{Len,Ptr} in _cgo_export.h

@mknyszek mknyszek moved this to All-But-Submitted in Go Compiler / Runtime Jan 22, 2025
@mknyszek mknyszek added this to the Backlog milestone Jan 22, 2025
@mknyszek mknyszek moved this to All-But-Submitted in Go Compiler / Runtime Jan 22, 2025
@github-project-automation github-project-automation bot moved this from All-But-Submitted to Done in Go Compiler / Runtime Feb 3, 2025
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 3, 2025
@dmitshur dmitshur modified the milestones: Backlog, Go1.25 Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

6 participants