veandco / go-sdl2

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

About mips cross-compilation #485

Closed mumbaicat closed 3 years ago

mumbaicat commented 3 years ago

WSL2 ubuntu Ubuntu 20.04.2 LTS go version go1.16.4 linux/amd64

GOOS=linux GOARCH=mipsle GOMIPS=softfloat CGO_ENABLED=1 CC=mipsel-linux-gnu-gcc go build

run it

# github.com/veandco/go-sdl2/sdl
In file included from /usr/include/SDL2/SDL_stdinc.h:31,
                 from /usr/include/SDL2/SDL_main.h:25,
                 from /usr/include/SDL2/SDL.h:32,
                 from ./sdl_wrapper.h:5,
                 from /mnt/c/go/gopath/src/github.com/veandco/go-sdl2/sdl/audio.go:4:
/usr/include/SDL2/SDL_config.h:4:10: fatal error: SDL2/_real_SDL_config.h: No such file or directory
    4 | #include <SDL2/_real_SDL_config.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
veeableful commented 3 years ago

Hi @mumbaicat! Have you tried compiling SDL2 from source? I have provided instructions below.

  1. Create a workspace directory and go to that directory.

    mkdir sdl2-builds
    cd sdl2-builds
  2. Download SDL2 and extract it.

    wget https://libsdl.org/release/SDL2-2.0.14.zip
    unzip SDL2-2.0.14.zip
  3. Install build tools

apt install -y make {gcc,g++}-mipsel-linux-gnu
  1. Create the build script (e.g. build-SDL2-linux-mipsel.sh) using the content below. I adapted this from our current build script for ARM static libraries so perhaps you may want to tweak it. After the script is created, run it with sh build-SDL2-linux-mipsel.sh.
    
    #!/usr/bin/env bash

TARGET="mipsel-linux-gnu" SDL2_VERSION=2.0.14 LIBDIR=build/.libs

cd SDL2-${SDL2_VERSION} rm -r build-linux-mipsel 2> /dev/null

export CC="${TARGET}-gcc" export CXX="${TARGET}-g++"

mkdir -p build-linux-mipsel && cd build-linux-mipsel ../configure --prefix="$HOME/.${TARGET}" --host="${TARGET}" --disable-video-wayland --disable-video-vivante --disable-video-rpi --enable-video-x11 --enable-video-opengl --disable-video-kmsdrm --disable-pulseaudio --enable-video-opengles make -j$(nproc) make install cp ${LIBDIR}/libSDL2.a ${LIBDIR}/libSDL2.a.debug ${TARGET}-strip ${LIBDIR}/libSDL2.a ${TARGET}-ranlib ${LIBDIR}/libSDL2.a

cd ..


5. Update `PKG_CONFIG_PATH` to include the path to the mipsel version of SDL2 in `~/.profile` using the following content. Then activate it with `source ~/.profile`

export PKG_CONFIG_PATH="$HOME/.mipsel-linux-gnu/lib/pkgconfig:$PKG_CONFIG_PATH"



6. Try building go-sdl2 again!
mumbaicat commented 3 years ago

It's running successfully. It's a perfect help. Thank you.