Open YievCkim opened 1 year ago
I forgot to say local run and compilation on FreeBSD AMD/64 work as expected. I add the go source file in the thread.
I would try to compile this file directly on target but go doesn't seems available on FreeBSD12. (And Xorg or wayland are not working on FreeBSD13 )
https://www.freshports.org/lang/go
// main.go
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()
println("create window")
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{50, 50, 200, 200}
colour := sdl.Color{R: 255, G: 80, B: 150, A: 255}
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 succeed to x-compile with clang using my sysroot so I don't think it comes from that:
#include <SDL2/SDL.h>
#include <stdio.h>
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
int main(int argc, char* args[]) {
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError());
return 1;
}
window = SDL_CreateWindow(
"hello_sdl2",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_SHOWN
);
if (window == NULL) {
fprintf(stderr, "could not create window: %s\n", SDL_GetError());
return 1;
}
screenSurface = SDL_GetWindowSurface(window);
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
SDL_UpdateWindowSurface(window);
SDL_Delay(2000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
mik@labo $ clang test_sdl.c -I ./freebsd-tree/usr/local/include -L ./freebsd-tree/usr/local/lib -l SDL2 --sysroot=./freebsd-tree --target=armv7-none-freebsd -o test_sdl
mik@labo $ file test_sdl
test_sdl: ELF 32-bit LSB executable, ARM, EABI5 version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 12.4 (1204500), FreeBSD-style, with debug_info, not stripped
If I try to x-compile the go program with the same options I get an error about sdl go module:
mik@labo $ CC=clang CGO_CFLAGS='--target=armv7-none-freebsd -l SDL2 -L ./freebsd-tree/usr/local/lib -I ./freebsd-tree/usr/local/include --sysroot=./freebsd-tree' GOARCH=arm GOARM=7 go build -v xcb.go
command-line-arguments
# command-line-arguments
./xcb.go:9:16: undefined: sdl.Init
./xcb.go:9:25: undefined: sdl.INIT_EVERYTHING
./xcb.go:12:12: undefined: sdl.Quit
./xcb.go:15:21: undefined: sdl.CreateWindow
./xcb.go:17:7: undefined: sdl.WINDOWPOS_UNDEFINED
./xcb.go:18:7: undefined: sdl.WINDOWPOS_UNDEFINED
./xcb.go:19:17: undefined: sdl.WINDOW_SHOWN
./xcb.go:32:14: undefined: sdl.Rect
./xcb.go:33:16: undefined: sdl.Color
./xcb.go:34:15: undefined: sdl.MapRGBA
./xcb.go:34:15: too many errors
Hi @MikHulk, unfortunately we don't have static libraries built for FreeBSD so the static compilation would fail but please let me know if the Linux one works for you.
Hi @veeableful, thank you ! I will try and keep you update.
I thought maybe I could build this missing lib.
Go version: go1.20.3 freebsd/amd64 Go-SDL2 version: github.com/veandco/go-sdl2 v0.4.35 SDL2 version: on host:
on target
OS: FreeBSD Architecture: armv7
When I try to build some program from Freebsd amd64 for FreeBSD armv7 I get errors.
With gcc as compiler:
As this error is related to some system headers I thought I had to give location of this header. So I have made an extract of the target system file:
I tried with clang as cgo compiler too:
without sysroot I get the same error above with gcc but given by clang:
I don't know if the problem comes from BSD or GO or else.
I think I going to try with a linux target, see if it works. But Help is very welcome.