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
Comments
I think singlep.go and test.go are 2 different programs. The first one prints:
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 |
Sorry, the code I was referring to is just down from that. The file singlep.go contains // package level data declarations serve as singleton instance variables // package level initialization can serve as constructor code // package level functions serve as methods for a package-as-a-singleton The file test.go contains: import ( func main() { 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%. |
Okay, first of all, having "module singlep" in go.mod says - 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. |
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. |
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. |
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? |
I am not even able to reproduce the error. So I cannot say whether it can be improved or not. |
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
)?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.
The text was updated successfully, but these errors were encountered: