electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
152 stars 29 forks source link

undefined symbol: eglGetProcAddress on Raspberry Pi 4 #137

Closed bizfish closed 1 month ago

bizfish commented 1 month ago

I'm trying to install for DRM and have followed the Option 3 steps in the RPi instructions and I'm getting the below error. I've tried a bunch of different cmake options for building raylib but nothing has gotten it working so far. I've tried on raspbian lite and on a full install of raspbian (autologin to CLI).

>> from raylib import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.11/site-packages/raylib/__init__.py", line 15, in <module>
    from ._raylib_cffi import ffi, lib as rl
ImportError: /home/pi/.local/lib/python3.11/site-packages/raylib/_raylib_cffi.abi3.so: undefined symbol: eglGetProcAddress
electronstudio commented 1 month ago

I’ve seen that error posted here before but I can’t remember if anyone managed to fix it. Raylib in DRM mode has historically been quite unreliable - I never got it to work on my Pi 3.

However those instructions do work for me on Pi 4 with Raspberry Pi OS 12 (bookworm) 64 bit. Is this version you are running?

in order for Raylib-Python-CFFI to compile, you do need a working installation of Raylib. Does your Raylib work, I.e, can you run the C examples that come with it?

bizfish commented 1 month ago

I can run the C examples without issue, and it is bookworm 64bit. Its a fully fresh install, maybe I'm missing some library or config setting? I am able to build with pip without error and install it to python but it just fails to import at runtime.

electronstudio commented 1 month ago

Does the LD preload fix here help? https://github.com/electronstudio/raylib-python-cffi/issues/77

bizfish commented 1 month ago

Using their preload fix I got: ImportError: /home/pi/.local/lib/python3.11/site-packages/raylib/_raylib_cffi.abi3.so: undefined symbol: glfwGetMonitorWorkarea Then I tried adding /usr/lib/aarch64-linux-gnu/libglfw.so to the preload too and I got this: ImportError: /home/pi/.local/lib/python3.11/site-packages/raylib/_raylib_cffi.abi3.so: undefined symbol: glfwGetPlatform I noticed glfwGetPlatform was added to GLFW in version 3.4 and the GLFW version that got installed (through apt as a dependency, maybe?) was 3.3. So I checked out glfw/master and built with BUILD_SHARED_LIBS and installed that. After that, this now works: LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libEGL.so /usr/lib/aarch64-linux-gnu/libgbm.so /usr/local/lib/libglfw.so" python3 examples/shapes/shapes_logo_raylib.py

electronstudio commented 1 month ago

Well done for getting it to work.

But that is quite strange. Raylib should be linking with its own internal copy of GLFW 3.4 (unless USE_EXTERNAL_GLFW is set) so it shouldn't need to load the system one. Maybe EGL links against the system GLFW, or vice versa?

electronstudio commented 1 month ago

OK I think I've solved the GLFW part of the problem.

The instructions tell you to sudo cp -r ../src/external/glfw/include/GLFW /usr/local/include/ which copies Raylib's internal GLFW header to the system so that raylib-python-cffi can find it when building, but that version doesn't match the system version. Raylib in DRM mode doesn't use GLFW at all so I think we can rm -rf /usr/local/include/GLFW and I'll remove that from the instructions.

electronstudio commented 1 month ago

The original problem is caused by pkg-config --libs raylib failing to include "-lgbm -ldrm -lEGL".

It looks like I was aware of this because the instructions say to set LDFLAGS... but then LDFLAGS is ignored. So I have no idea how this worked for me a few weeks ago and now it doesn't.

I'm not sure what the cleanest fix is. Probably easiest to manually patch the pkg-config file.

electronstudio commented 1 month ago

I think easiest is to build a shared version of raylib rather than static. The shared libraries dont have problems finding other shared libraries. This produces wheels that require raylib shared library to be installed but I think that's fine if people are building from source anyway.

I have updated instructions, let me know if they work: https://github.com/electronstudio/raylib-python-cffi/blob/master/RPI.rst#option-3-compile-raylib-from-source-drm-mode

bizfish commented 1 month ago

The new instructions work great!