veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.17k stars 219 forks source link

undefined: sdl.Init #559

Closed vault-thirteen closed 1 year ago

vault-thirteen commented 1 year ago

Go version: 1.20. Go-SDL2 version: v0.4.34. SDL2 version: 2.26.5. OS: Windows 10. Architecture: Intel x86-64.

I have installed a Cygwin64, added it's bin folder to PATH environment variable. I have installed SDL and added it to PATH variable. I have created a module and pulled a vendor folder with your library. I can even jump to the sdl.Init function from the editor, the code is reachable. But when I run the main function it says that it does not know about the sdl package.

package main

import (
    "log"

    "github.com/veandco/go-sdl2/sdl"
)

func main() {
    var err = sdl.Init(sdl.INIT_EVERYTHING)
    if err != nil {
        log.Fatal(err)
    }
}

.\main.go:10:16: undefined: sdl.Init .\main.go:10:25: undefined: sdl.INIT_EVERYTHING

Compilation finished with exit code 1

P. S.

Contents of the module file:

module test/sdl-a

go 1.20

require github.com/veandco/go-sdl2 v0.4.34

Looks like, v0.4.34 is not working.

vault-thirteen commented 1 year ago

When I try the latest unstable version, which is not yet published,

go get -v github.com/veandco/go-sdl2/sdl@master go: upgraded github.com/veandco/go-sdl2 v0.4.34 => v0.5.0-alpha.4.0.20230209044354-a8580f5a99af

it downloads some non-stable ... code and tells about other errors like:

# github.com/veandco/go-sdl2/sdl vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:11:8: undefined: PIXELFORMAT_UNKNOWN vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:12:8: undefined: PIXELFORMAT_INDEX1LSB vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:13:8: undefined: PIXELFORMAT_INDEX1MSB vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:14:8: undefined: PIXELFORMAT_INDEX4LSB vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:15:8: undefined: PIXELFORMAT_INDEX4MSB vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:16:8: undefined: PIXELFORMAT_INDEX8 vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:17:8: undefined: PIXELFORMAT_RGB332 vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:18:8: undefined: PIXELFORMAT_RGB444 vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:57:36: undefined: PixelFormatConstant vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:97:9: undefined: PixelFormatConstant vendor\github.com\veandco\go-sdl2\sdl\pixelformatconstant_string.go:18:8: too many errors

Compilation finished with exit code 1

veeableful commented 1 year ago

Hi @vault-thirteen, thanks for reporting this issue! Could you try the updated Windows installation process in README.md? I suspect the errors were caused by go being unable to find the MinGW tools. Updating the Path environment variable to have the MinGW's or Cygwin's bin directory should fix it.

vault-thirteen commented 1 year ago

Hello @veeableful. Thank you for a prompt response ! The thing is that I already had Cygwin's bin folder in my PATH environment variable. I will try to re-install everything using the new instructions.

vault-thirteen commented 1 year ago

x86_64-12.2.0-release-posix-seh-msvcrt-rt_v10-rev2.7z x86_64-12.2.0-release-posix-seh-ucrt-rt_v10-rev2.7z x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z x86_64-12.2.0-release-win32-seh-ucrt-rt_v10-rev2.7z

Which variant of the build do I need on Windows 10 ? I guess, that POSIX is a wrong one for Windows OS, right ? MSVCRT or UCRT ?

veeableful commented 1 year ago

Hi @vault-thirteen, you should be able to use any one of them I think but I used the posix ucrt. Let me know if it works for you too.

vault-thirteen commented 1 year ago

OK. Thanks.

I have found that both Windows 10 and Microsoft Visual Studio use UCRT by default, instead of an outdated MSVCRT. https://stackoverflow.com/questions/67848972/differences-between-msvcrt-ucrt-and-vcruntime-libraries

I will try this UCRT first.

vault-thirteen commented 1 year ago

https://github.com/libsdl-org/SDL/releases

SDL2-devel-2.26.5-mingw.zip SDL2-devel-2.26.5-VC.zip

Which type of SDL library do I need ? @veeableful

veeableful commented 1 year ago

Hi @vault-thirteen, it should be MinGW version.

vault-thirteen commented 1 year ago

What is the difference between i686-w64 and x86_64 ? I have always thought that it is the same. @veeableful

veeableful commented 1 year ago

Hi @vault-thirteen, i686 is for 32-bit processor and x86_64 is for 64-bit processor.

vault-thirteen commented 1 year ago

Yeah, I know it, but there is a w64 postfix meaning that it is 64-bit (?) in i686-w64.

veeableful commented 1 year ago

I'm not entirely sure but I think it's just part of the MinGW name.

vault-thirteen commented 1 year ago

Looks like there is no error now. The program compiles and runs. Thank you so much ! @veeableful

veeableful commented 1 year ago

No problem! I'm glad that I could help.