-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: inconsistent compiler behaviour when compiling a C.struct #52611
Comments
Additional information - can confirm that I've been able to reproduce the problem on:
|
root cause is the files order, last file |
Oh, right .. if I build with the source files specified individually and main.go as the last file it compiles ok.
Thanks - I'll dig a bit into the options to see if there's an alternative to manually specifying the files, but this issue can be closed. |
Ref. go/issues/38186: cmd/compile: builds not reproducible if input file order is different
|
Reopening because I think there is still a bug here. Renaming the source files in a package should not have a significant effect on the result. It certainly shouldn't change between a successful build and a failing build. |
When phrased like that it does sound like there may be more to it - it was certainly unexpected behaviour and the workaround is inconvenient even in such a small project. Some additional info - building with the succeeded:
failed:
|
Change https://go.dev/cl/404497 mentions this issue: |
Ok, I can confirm that 404497: cmd/cgo: dont override declared struct type seems to fix the immediate problem:
I'm still a bit puzzled about why
when the only mention in time_profiles.go is as a func parameter:
|
Lines 2523 to 2527 in a131fd1
cgo dont know player how to use the struct declaration, in pure c, empty declaration is use for previously-declared struct, most of time use for handle. |
Fixes golang#52611 Change-Id: I835df8d6a98a37482446ec00af768c96fd8ee4fe GitHub-Last-Rev: ea54dd6 GitHub-Pull-Request: golang#52733 Reviewed-on: https://go-review.googlesource.com/c/go/+/404497 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dexter Ouyang <kkhaike@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Alex Rakoczy <alex@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When building a shared-lib/DLL with
cgo
it fails to compile with the following error:if the struct
C.struct_TimeProfile
is defined in main.go and is passed as an argument to a function in another file in the the same (main
) package. However, it compiles successfully if:C.struct_TimeProfile
is inmain.go
C.struct_TimeProfile
is in in an entirely different Go fileC.struct_TimeProfile
is unpacked to a Go struct in main.goOther:
C.struct_TimeProfile
is identical (other than names) to another struct (C.struct_Card)
that does not show the same behaviourI've attached tar.gz files with minimal examples that fail and succeed.
What did you expect to see?
Compiles without error irrespective of where the function is located
What did you see instead?
Compiles with the following error unless the func is a specific file:
fails.tar.gz
succeeds.tar.gz
The text was updated successfully, but these errors were encountered: