0

When I try to build a Go application on an amd64 host for a Raspberry-Pi 2 I get this error:

...
cp $WORK/b058/_pkg_.a /.cache/go-build/23/23b77813791e651c39389b15d7f9981669cdee14675f76b632daaa86ced9fc66-d
# internal
# github.com/veandco/go-sdl2/img /usr/lib/gcc-cross/arm-linux-gnueabi/10/../../../../arm-linux-gnueabi/bin/ld: cannot find -lz /usr/lib/gcc-cross/arm-linux-gnueabi/10/../../../../arm-linux-gnueabi/bin/ld: cannot find -liconv /usr/lib/gcc-cross/arm-linux-gnueabi/10/../../../../arm-linux-gnueabi/bin/ld: cannot find -lbcm_host /usr/lib/gcc-cross/arm-linux-gnueabi/10/../../../../arm-linux-gnueabi/bin/ld: cannot find -lvcos /usr/lib/gcc-cross/arm-linux-gnueabi/10/../../../../arm-linux-gnueabi/bin/ld: cannot find -lvchiq_arm collect2: error: ld returned 1 exit status 
...

Conditions Docker container with Debian 10 (Bullseye) on an amd64 Ubuntu system

go.mod:

module example.com/sdl-example

go 1.19

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

Dockerfile:

FROM golang:1.19-bullseye

RUN dpkg --add-architecture armhf && \
    apt-get update && apt-get upgrade -y && \
    apt-get install -y \
    apt-utils \
    build-essential \
    glibc-source \
    libc6-armhf-cross \
    libc6-dev-armhf-cross \
    libc6-dev:armhf \
    zlib1g-dev:armhf \
    cmake:armhf \
    autoconf:armhf \
    libtool:armhf \
    gcc-arm-linux-gnueabi \
    crossbuild-essential-armhf \
    binutils-arm-linux-gnueabi \
    libsdl2-dev:armhf \
    libsdl2-ttf-dev:armhf \
    libsdl2-image-dev:armhf

RUN mkdir /.cache && chmod a+rwx /.cache
WORKDIR /build

Build-Script:

#!/bin/bash

export GOOS=linux
export GOARCH=arm
export GOARM=6
export CGO_ENABLED=1
export CC=arm-linux-gnueabi-gcc
export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig
export LD=arm-linux-gnueabi-ld
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/arm-linux-gnueabi/lib

go mod download -x \
    && echo -e "Verify..." \
    && go mod verify \
    && echo "OK"

go build -v -work -x -tags static -o builds/arm5

Example main.go to reproduce the error:

package main

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

func main() {
    if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
        panic(err)
    }
    defer sdl.Quit()

    window, err := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
        800, 600, sdl.WINDOW_SHOWN)
    if err != nil {
        panic(err)
    }
    defer window.Destroy()

    surface, err := window.GetSurface()
    if err != nil {
        panic(err)
    }
    surface.FillRect(nil, 0)

    rect := sdl.Rect{0, 0, 200, 200}
    colour := sdl.Color{R: 255, G: 0, B: 255, A: 255} // purple
    pixel := sdl.MapRGBA(surface.Format, colour.R, colour.G, colour.B, colour.A)
    surface.FillRect(&rect, pixel)
    window.UpdateSurface()

    running := true
    for running {
        for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
            switch event.(type) {
            case *sdl.QuitEvent:
                println("Quit")
                running = false
                break
            }
        }
    }
}

I think, that the error occurs every time if sdl2 is compiled static. I am afraid, that I have to add the missing libs manualy, in case, they are not provided by the linux distribution?

bytecounter
  • 133
  • 2
  • 11
  • Including some sample code that we can compile to reproduce this behavior would make it much easier for us to help out. – larsks Apr 08 '23 at 11:37
  • @larsks: I have added a code example. I think, it occurs every time when compiling static a code with sdl. – bytecounter Apr 10 '23 at 05:58

0 Answers0