Skip to content
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

Need Help: Cross-Compile to MIPS Architecture #447

Open
Zaya6 opened this issue Jan 28, 2020 · 7 comments
Open

Need Help: Cross-Compile to MIPS Architecture #447

Zaya6 opened this issue Jan 28, 2020 · 7 comments

Comments

@Zaya6
Copy link

Zaya6 commented Jan 28, 2020

For a hobby project I've been trying to create a program to run on the rg350 handheld, with a jz4770 processor. When I try to build I get these errors:

./hey.go:11:12: undefined: sdl.Init
./hey.go:11:21: undefined: sdl.INIT_EVERYTHING
./hey.go:14:8: undefined: sdl.Quit
./hey.go:16:17: undefined: sdl.CreateWindow
./hey.go:18:3: undefined: sdl.WINDOWPOS_UNDEFINED
./hey.go:19:3: undefined: sdl.WINDOWPOS_UNDEFINED
./hey.go:21:3: undefined: sdl.WINDOW_FULLSCREEN
./hey.go:36:19: undefined: sdl.CreateRenderer
./hey.go:36:50: undefined: sdl.RENDERER_ACCELERATED
./hey.go:47:22: undefined: sdl.Rect
./hey.go:47:22: too many errors

Building regularlly works just fine. Btw I'm pretty new to the go language itself and any help would be greatly appreciated.

@veeableful
Copy link
Contributor

Hi @Zaya6, do you already have SDL2 compiled for MIPS architecture? If so, what happens if you run go get -v github.com/veandco/go-sdl2/sdl?

@geniot
Copy link

geniot commented Nov 25, 2022

So I went a bit further than this :) Obviously you need a toolchain to cross-compile.
The error that I'm getting:
mipsel-gcw0-linux-uclibc-gcc: error: unrecognized command line option '-mno-odd-spreg'

Do you know where no-odd-spreg option is set? Why is it set and why my toolchain's mipsel gcc doesn't recognize it?

@gen2brain
Copy link
Collaborator

@geniot no-odd-spreg is set in Go, here https://github.com/golang/go/blob/master/src/cmd/cgo/gcc.go#L1639 depends if GOMIPS is hardfloat or softfloat, that also defaults in GCC for 32bit arch (hard-float), see here https://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html.

How did you try to build, did you manage to build and install SDL2 first?

@geniot
Copy link

geniot commented Nov 26, 2022

Thanks @gen2brain for replying.
What I'm trying to achieve: using Go create a simple SDL2 demo for my PocketGo2v2 which has MIPS architecture.
What I did:

  1. simple "helloworld.go" on my Linux host - OK
  2. same with GOARCH=mipsle, upload, run on PocketGo - OK
  3. simple SDL2 red rectangle program taken from your examples (on my host) - OK
  4. same with cross compilation - FAIL

My env variables:
CC=/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-gcc
CGO_CFLAGS=-I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include -D_REENTRANT
CGO_ENABLED=1
CGO_LDFLAGS=-L/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/lib -lSDL2
GOARCH=mipsle
GOOS=linux

I get an error:
mipsel-gcw0-linux-uclibc-gcc: error: unrecognized command line option '-mno-odd-spreg'

Firmware that I have:
https://github.com/Ninoh-FOX/POCKETGO2_ROGUE_CFW
Toolchain that I'm using:
https://github.com/Ninoh-FOX/toolchain

I looked at the gcc.go code. Do you know how to force gomips=softfloat?
Update:
I added GOMIPS=softfloat to my env variables. Now the compilation is really running! But I'm getting this:

# github.com/veandco/go-sdl2/sdl
In file included from /usr/include/SDL2/SDL.h:38:0,
                 from ./sdl_wrapper.h:5,
                 from ../pkg/mod/github.com/veandco/[email protected]/sdl/audio.go:4:
/usr/include/SDL2/SDL_cpuinfo.h:64:23: fatal error: immintrin.h: No such file or directory
 #include <immintrin.h>
                       ^
compilation terminated.

@gen2brain
Copy link
Collaborator

@geniot Now you should compile SDL2 with that same toolchain. pkg-config is now trying to use your system SDL2, which is not good. Point PKG_CONFIG_PATH and PKG_CONFIG_LIBDIR to i.e. /opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/lib/pkgconfig. If you have mipsel-gcw0-linux-uclibc-pkg-config, set that as PKG_CONFIG though I don't think it is necessary to have.

The goal is to build SDL2 for mipsel, and to tell pkg-config where is that build installed, go-sdl2 will just use pkg-config: sdl2. You can manually check the output with pkg-config --cflags --libs sdl2, you are also free to change .pc files in lib/pkgconfig.

@gen2brain
Copy link
Collaborator

Btw. if that toolchain is using GCC-4.3 that is the reason why you don't have -mno-odd-spreg, the GCC is too old. You can either build/install some newer toolchain, or you can hack the Go source and use that build instead. That is if the device actually has support for hard float.

@geniot
Copy link

geniot commented Nov 26, 2022

Hurray! It's working! Thanks a lot! Now I can write a retro emulator in Go, test it on my laptop and then compile it for PocketGo.

red

To get it working I only had to add PKG_CONFIG:
env_vars

The build log has a lot of warnings like this:
/opt/gcw0-toolchain/usr/lib/gcc/mipsel-gcw0-linux-uclibc/4.9.1/../../../../mipsel-gcw0-linux-uclibc/bin/ld: Warning: $WORK/b001/exe/a.out uses hard float, /tmp/go-link-2142246393/go.o uses soft float

But I guess I'm ok with this.

The execution on PocketGo also has some dev/dri warnings:

POCKETGO2V2:/media/data/local/home # ./go_build_pgtest_cross 
The path /dev/dri/ cannot be opened or is not available
The path /dev/dri/ cannot be opened or is not available
fbdev_display succesful
Kernel: Vivante GPL kernel driver 4.6.6.1381
Physical address of internal memory: 00000000
* Video memory:
  Internal physical: 0x00000000
  Internal size: 0x00000000
  External physical: 00000000
  External size: 0x00000000
  Contiguous physical: 0x8c7efb00
  Contiguous size: 0x00400000
Succesfully opened device
native_fbdev: 2 buffers of 320x240
Framebuffer format: 6, flip_rb=0
Framebuffer format: 6, flip_rb=0

So, to sum up: I didn't have to compile SDL2 for MIPS. I guess because it's already part of the toolchain or operating system (on PocketGo) and pkg-config knows about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants