Skip to content

go: Inconsistent operational results due to different environments(windows,linux) #66798

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

Closed
godcong opened this issue Apr 12, 2024 · 2 comments
Closed

Comments

@godcong
Copy link

godcong commented Apr 12, 2024

Go version

1.21.0 1.22.0 1.22.1 1.22.2

Output of go env in your module/workspace:

all env printed at name run [platform] go [version]

https://github.com/godcong/cgoenv/actions/runs/8660795647/job/23749374671
https://github.com/godcong/cgoenv/actions/runs/8660795645/job/23749373828
https://github.com/godcong/cgoenv/actions/runs/8660795643/job/23749373813
https://github.com/godcong/cgoenv/actions/runs/8660795642/job/23749374674

What did you do?

example in two files:

package main

import "fmt"

func main() {
	fmt.Println("[MAIN] Hello, World!")
}
package main

import "C"
import "fmt"

func init() {
	fmt.Println("[OTHER] Import C and init in other.go")
}

When I run the program, windows executes init().
But, linux skips the execution of init().

What did you see happen?

in windows:
[OTHER] Import C and init in other.go
[MAIN] Hello, World!

in linux:
[MAIN] Hello, World!

What did you expect to see?

In different operating environments the same result can be outputted

@seankhliao
Copy link
Member

the CGO_ENABLED values are different in your env.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
@zigo101
Copy link

zigo101 commented Apr 12, 2024

@godcong an import "C" line implies the //go:build cgo build constraint: https://pkg.go.dev/cmd/cgo

The special import "C" implies the "cgo" build constraint, as though the file also said "//go:build cgo". Therefore, if cgo is disabled, files that import "C" will not be built by the go tool.

@golang golang locked and limited conversation to collaborators Apr 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants