Skip to content

crypto/x509: cgo errors on for loop initial declarations with gcc pre-C99 #24425

Closed
@avinashrd

Description

@avinashrd

Please answer these questions before submitting your issue. Thanks!

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

1.10

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN="/Users/avinashrd/Downloads/projects/golang/bin"
GOCACHE="/Users/avinashrd/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/avinashrd/Downloads/projects/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="/usr/local/Cellar/gcc49/4.9.1/bin/gcc-4.9"
CXX="/usr/local/Cellar/gcc49/4.9.1/bin/g++-4.9"
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"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/var/folders/w8/y97pxwvj35xcsw9vmh2s3gzr0000gn/T/go-build181075919=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

try to run the application in Jetbrains GoLand editor

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

expected to see the valid output

What did you see instead?

/usr/local/opt/go/libexec/src/crypto/x509/root_cgo_darwin.go:104:2: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
for (int i = 0; i < numDomains; i++) {
^
/usr/local/opt/go/libexec/src/crypto/x509/root_cgo_darwin.go:104:2: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
/usr/local/opt/go/libexec/src/crypto/x509/root_cgo_darwin.go:112:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
for (int j = 0; j < numCerts; j++) {

Activity

changed the title [-]getting an error for simple go program with for loop in MAC OSX 10.13.13[/-] [+]crypto/x509: getting an error for simple go program with for loop in MAC OSX 10.13.13[/+] on Mar 16, 2018
added
NeedsFixThe path to resolution is known, but the work has not been done.
on Mar 16, 2018
added this to the Go1.11 milestone on Mar 16, 2018
ianlancetaylor

ianlancetaylor commented on Mar 16, 2018

@ianlancetaylor
Contributor

Thanks. This is happening because you are running quite an old version of GCC. I'll send a fix.

gopherbot

gopherbot commented on Mar 16, 2018

@gopherbot
Contributor

Change https://golang.org/cl/101215 mentions this issue: crypto/x509: don't require C99 mode in Darwin cgo code

changed the title [-]crypto/x509: getting an error for simple go program with for loop in MAC OSX 10.13.13[/-] [+]crypto/x509: cgo errors on for loop initial declarations with gcc pre-C99[/+] on Mar 16, 2018
avinashrd

avinashrd commented on Mar 17, 2018

@avinashrd
Author

@ianlancetaylor

Thanks for the reply.
If I update my GCC using brew, will that fix the issue?

I didn't understand the comment by @gopherbot .

FiloSottile

FiloSottile commented on Mar 17, 2018

@FiloSottile
Contributor

@avinashrd Yes, if you install a more recent version of GCC (for example brew install gcc which will currently install 7.3) and set it as your CC/CXX environment variables, it should fix your issue.

@gopherbot was just reporting that we are working on a fix in Go, but that will not be available until Go 1.11, and it might not be enough to make GCC 4.9 work anyway.

avinashrd

avinashrd commented on Mar 18, 2018

@avinashrd
Author

I updated to 7.3 as suggested and ran the same program. I am getting this error now

crypto/x509

In file included from /System/Library/Frameworks/Security.framework/Headers/AuthSession.h:32:0,
from /System/Library/Frameworks/Security.framework/Headers/Security.h:43,
from /usr/local/Cellar/go/1.10/libexec/src/crypto/x509/root_cgo_darwin.go:17:
/System/Library/Frameworks/Security.framework/Headers/Authorization.h:193:7: error: variably modified 'bytes' at file scope
char bytes[kAuthorizationExternalFormLength];
^~~~~

Go Env :

GOARCH="amd64"
GOBIN="/Users/xxx/Downloads/projects/golang/bin"
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxxx/Downloads/projects/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="/usr/local/Cellar/gcc/7.3.0_1/bin/gcc-7"
CXX="/usr/local/Cellar/gcc/7.3.0_1/bin/g++-7"
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"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/var/folders/w8/y97pxwvj35xcsw9vmh2s3gzr0000gn/T/go-build575805343=/tmp/go-build -gno-record-gcc-switches -fno-common"

locked and limited conversation to collaborators on Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.OS-Darwin

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @FiloSottile@ianlancetaylor@avinashrd@gopherbot

        Issue actions

          crypto/x509: cgo errors on for loop initial declarations with gcc pre-C99 · Issue #24425 · golang/go