veandco / go-sdl2

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

"undefined reference" when trying to compile a 32-bit executable for Linux. #517

Closed IoIxD closed 2 years ago

IoIxD commented 2 years ago

I get a very strange error when trying to compile a program using GOOS=386 that I don't get otherwise...

gavin@jeff ~/P/SDLTest> go build .
gavin@jeff ~/P/SDLTest> GOARCH=386 go build .
# github.com/ioixd/textadventure/src
src/background.go:7:30: undefined: sdl.Surface
src/background.go:9:8: undefined: sdl.Rect
src/background.go:10:8: undefined: sdl.Rect
src/background.go:11:8: undefined: sdl.Rect
gavin@jeff ~/P/SDLTest [2]> 

A copy of all the test project is available here

gavin@jeff ~/P/SDLTest> uname -a
Linux jeff 5.15.28-1-MANJARO #1 SMP PREEMPT Fri Mar 11 14:12:57 UTC 2022 x86_64 GNU/Linux
veeableful commented 2 years ago

Hi @IoIxD, could it be that the 32-bit version of SDL2 is not installed in the system? If you have it installed, I think it should work.

Another way you can try is to compile it statically. The following command would make it use the pre-compiled static libraries that we provide.

CGO_ENABLED=1 CC=gcc GOOS=linux GOARCH=386 go build -tags static -ldflags "-s -w" -a
gen2brain commented 2 years ago

@IoIxD You are missing CGO_ENABLED=1. When you are changing GOARCH to 386 you are cross-compiling, which means Go is running with CGO_ENABLED=0. Add CGO_ENABLED=1 so you can see the real error messages. i.e. missing 32bit lib etc.

IoIxD commented 2 years ago

CGO_ENABLED helped; actually I didn't get another error it was just that. I'm now getting a floating point exception so maybe this doesn't have great 32-bit support after all but at least it compiles. Thanks!