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

C source files not allowed error #36333

Closed
petelomax opened this issue Dec 31, 2019 · 7 comments
Closed

C source files not allowed error #36333

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

Comments

@petelomax
Copy link

petelomax commented Dec 31, 2019

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

go version go1.11 windows/amd64

Does this issue reproduce with the latest release?

Yes, go version go1.13.5 windows/amd64 (I manually recreated go.mod)

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

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Pete\AppData\Local\go-build
set GOENV=C:\Users\Pete\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Pete\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Program Files (x86)\Phix\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Pete\AppData\Local\Temp\go-build126546934=/tmp/go-build -gno-record-gcc-switches

What did you do?

Running the "Packages as singletons" code from https://rosettacode.org/wiki/Singleton#Go

I originally put singlep.go in the current directory, before moving it to %GOPATH%\src\singlep\singlep.go
There were a few possibly/probably ill-advised "go (build|install|mod init) singlep[.go]" before/after said move, then:

C:\Program Files (x86)\Phix>go run test.go
test.go:5:5: C source files not allowed when not using cgo or SWIG: test.c

C:\Program Files (x86)\Phix>type go.mod
module singlep

C:\Program Files (x86)\Phix>del go.mod

C:\Program Files (x86)\Phix>go run test.go
2 3
1

So: my problem is solved, however that "C source files not allowed" error caused by that rogue go.mod is pretty icky imo. It ain't going to hurt me should nothing be done about this, but I assume it is better to speak up when I think something is wrong.

@agnivade
Copy link
Contributor

agnivade commented Jan 4, 2020

I think singlep.go and test.go are 2 different programs. The first one prints:

2020/01/04 11:48:16 trying to claim blue
2020/01/04 11:48:16 tried blue. instance: blue
2020/01/04 11:48:16 trying to claim red
2020/01/04 11:48:16 tried red. instance: blue
2020/01/04 11:48:16 after trying both, instance = blue

There also seems to be a test.c in your current directory. Can you tell us the steps you did again ? What is the test.go file ? and what is the test.c file ? Did you run go mod init ?

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 4, 2020
@petelomax
Copy link
Author

Sorry, the code I was referring to is just down from that. The file singlep.go contains
`package singlep

// package level data declarations serve as singleton instance variables
var X, Y int

// package level initialization can serve as constructor code
func init() {
X, Y = 2, 3
}

// package level functions serve as methods for a package-as-a-singleton
func F() int {
return Y - X
}`

The file test.go contains:
`package main

import (
"fmt"
"singlep"
)

func main() {
// dot selector syntax references package variables and functions
fmt.Println(singlep.X, singlep.Y)
fmt.Println(singlep.F())
}`

There is indeed a completely unrelated test.c in that directory, from last August, it did not appear to try/fail to overwrite it. Pretty sure there was a go mod init involved, sorry I can't be more precise about the exact steps, and I suspect I would struggle to reproduce things now that I have stuff in %GOPATH%.

@agnivade
Copy link
Contributor

agnivade commented Jan 5, 2020

Okay, first of all, having "module singlep" in go.mod says - build command-line-arguments: cannot load singlep: malformed module path "singlep": missing dot in first path element.

Also, you didn't mention the directory structure, so I just put main.go in the top-level directory and singlep in a sub-package.

After I changed the module name to github.com/user/somepackage, and then the import path to github.com/user/somepackage/singlep, it works fine.

Having a random test.c file in the directory also does not affect the results.

I think there were some other things that there there in the directory which caused this issue. I'm afraid you would have to be more precise than this. Otherwise, since the problem seems to have gone away for you now, feel free to close this and re-open with exact instructions when you see it happen again.

@agnivade agnivade added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 5, 2020
@petelomax
Copy link
Author

petelomax commented Jan 5, 2020

Thanks for looking. It may be worth mentioning that I don't have a gccgo.com/exe/bat/whatever anywhere on by system (according to procmon) and that with the rogue go.mod it fails on C:\Go\src\singlep, period, whereas after deleting it I get the same failure but then it carries on to find C:\Users\Pete\go\src\singlep... Btw there was no directory structure, I put both test.go and singlep.go in the same directory (an old one full of other crud), though I'm still getting exactly the same error message (still C source files not allowed) now singlep is somewhere more sensible. In both cases (with and without that go.mod) it looks for gccgo.* and it seems that the presence of that go.mod stops it looking in users\Pete. Anyway, this is only about improving the error message, so if that is not possible, case closed.

@agnivade
Copy link
Contributor

agnivade commented Jan 6, 2020

First, we need to be able to reliably reproduce it to understand what's happening. Then see if it is indeed about improving the error message or not. Before, you haven't mentioned this is somehow related to gccgo. Also, I am not sure how it will work by putting both the files in the same directory, because both are in different packages as mentioned in your comment.

The presence of a go.mod file will stop it there because the Go command assumes it's in module mode and tries to do its job in that mode. Without that, it is in GOPATH mode and goes on to look in the GOPATH for the unresolved dependencies.

I still think without more accurate steps to reproduce this, it is difficult to make progress on this further.

@ianlancetaylor for gccgo.

@petelomax
Copy link
Author

I just had a hunch that maybe you are getting a completely different error message to me because I don't have a gccgo, I only spotted that fact in procmon yesterday. I had no idea packages could not be put in the same directory, or that "module mode" vs "GOPATH mode" even existed. I suppose my other question is whether you think the error you /are/ getting c/should be improved?

@agnivade
Copy link
Contributor

agnivade commented Jan 7, 2020

I am not even able to reproduce the error. So I cannot say whether it can be improved or not.

@golang golang locked and limited conversation to collaborators Mar 19, 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

3 participants