go-gl / gl

Go bindings for OpenGL (generated via glow)
MIT License
1.08k stars 74 forks source link

Doesn't work on Windows 10 #156

Closed robert-dzikowski closed 1 year ago

robert-dzikowski commented 1 year ago

I can't compile any program on Windows 10 that uses this library

λ go build
package github.com/go-gl/example/gl41core-cube
        imports github.com/go-gl/gl/v4.1-core/gl: build constraints exclude all Go files in C:\Users\Robert\go\pkg\mod\github.com\go-gl\gl@v0.0.0-20211210172815-726fda9656d6\v4.1-core\gl

λ go build
package github.com/icexin/gocraft
        imports github.com/go-gl/gl/v3.3-core/gl: build constraints exclude all Go files in C:\Users\Robert\go\pkg\mod\github.com\go-gl\gl@v0.0.0-20211210172815-726fda9656d6\v3.3-core\gl
robert-dzikowski commented 1 year ago

That problem doesn't occur in github.com/go-gl/glfw/v3.3/glfw although it was present in version 3.2 of that library.

dmitshur commented 1 year ago

What version of Go are you using? Is there a C compiler in %PATH%? What happens if you set CGO_ENABLED to 1 and try go build again?

robert-dzikowski commented 1 year ago

I don't think I have C compiler, what C compiler I should use for Windows? I use go1.20.5 windows/amd64 I set CGO_ENABLED=1 and nothing changed.

dmitshur commented 1 year ago

I don't think I have C compiler, what C compiler I should use for Windows?

This package uses cgo, so a C compiler is required. See requirements at https://github.com/go-gl/gl#readme.

https://go.dev/wiki/cgo#windows lists mingw-w64 as one example of a C compiler that can be used on Windows. There may be more options available.

I set CGO_ENABLED=1 and nothing changed.

That's unexpected. It you set CGO_ENABLED to 1 and try to build this package (or something that imports it), and a C compiler is not available in PATH, it should fail with something like:

$ CGO_ENABLED=1 go build github.com/go-gl/gl/v3.3-core/gl
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%
Folium1 commented 1 year ago

On macOS I use mingw-w64 for building, here my building command:

b: @CGO_ENABLED=1 CC=/opt/homebrew/bin/x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build -tags=gl_v4_6_core -o install.exe

robert-dzikowski commented 1 year ago

It works now. I used GCC from https://winlibs.com and set CGO_ENABLED=1.