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

"go get" is deprecated, how to install go-sdl2 #526

Closed djnjbjb closed 2 years ago

djnjbjb commented 2 years ago

In the document, it says I can install by

go get -v github.com/veandco/go-sdl2/{sdl,img,mix,ttf}

But, with Go 1.18, the command results in" 'go get' is no longer supported... "


Then I try

go install -v github.com/veandco/go-sdl2/{sdl,img,mix,ttf}@v0.4.0

But it results in "package github.com/veandco/go-sdl2/sdl is not a main package ..."


How to install go-sdl2 with Go 1.18?

veeableful commented 2 years ago

Hi @djnjbjb, sorry the instructions aren't clear! Did you run it within your Go module? If not, you can create a module by creating a directory and then run go mod init [module name] inside it. After that, you should be able to run the go get and then go install commands though you should omit the @v0.4.0 as that version is outdated. Finally you can build your program using go build.

There's also another way where you can simply import the package in your source code and running go mod tidy will take care of downloading your dependencies after which you can run go build.

djnjbjb commented 2 years ago

Thank you. I'm new to Go and not familiar with Go module. I'll try “go mod init [module name]”.

djnjbjb commented 2 years ago

I have learnt go module these days. The "go mod init - go get" way works. Thank you again.

I still do not understand "go install" now. With git module, "go get" works fine. I didn't use "go install" and don't understand what does "go install" do.

djnjbjb commented 2 years ago

After some searching, I kind of understand "go install" by now. go install is for executables.

Executables are normally located in $GoPath/bin. I can use "go install" to install a web library. "go install" equals 2 steps: 1. use "go get" to download the library; 2. built a executable and put it in $GoPath/bin. I can also use "go install" to install my own project to $GoPath/bin. (This time, "go install" equals: 1. "go build"; 2. put executable in $GoPath/bin.)

So, if i use go install for go-sdl2 -- "go install github.com/veandco/go-sdl2/{sdl,img,mix,ttf}". It would result in " *** is not a main package". Executable needs a main pacakge. But go-sdl2 is a library with no executable(which means no main package).

More about "go install" can be found in

Deprecation of 'go get' for installing executables
https://go.dev/doc/go-get-install-deprecation