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

rPi, ubuntu 18.04, 64bit, "undefined symbol: eglGetProcAddress" #77

Closed rwsfisker closed 2 years ago

rwsfisker commented 2 years ago

I'm building to support DRM mode (for display on 3.5" TFT). Steps:

Build / install raylib DRM, Release, PIC:

home> git clone https://github.com/raysan5/raylib.git
home> cd raylib
home/raylib> cmake -DCMAKE_BUILD_TYPE=Release -DPLATFORM="DRM" -Wno-dev -GNinja -DBUILD_EXAMPLES=1 -DWITH_PIC=1 -B build/static
home/raylib> cmake --build build/static
home/raylib> sudo cmake --install build/static

Build / install raylib-python-cffi

home> sudo pip3 install --no-binary raylib --upgrade --force-reinstall raylib==v4.2.0.0.dev2

Attempt to run example/shapes/shapes_logo_raylib.py

~/raylib-python-cffi$ python3 examples/shapes/shapes_logo_raylib.py 
Traceback (most recent call last):
  File "/home/roger/raylib-python-cffi/examples/shapes/shapes_logo_raylib.py", line 6, in <module>
    from pyray import *
  File "/usr/local/lib/python3.10/dist-packages/pyray/__init__.py", line 15, in <module>
    from raylib import rl, ffi
  File "/usr/local/lib/python3.10/dist-packages/raylib/__init__.py", line 15, in <module>
    from ._raylib_cffi import ffi, lib as rl
ImportError: /usr/local/lib/python3.10/dist-packages/raylib/_raylib_cffi.cpython-310-aarch64-linux-gnu.so: undefined symbol: eglGetProcAddress

LD_PRELOAD of missing libraries FIXES

LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libEGL.so /usr/lib/aarch64-linux-gnu/libgbm.so" python3 examples/shapes/shapes_logo_raylib.py 
rwsfisker commented 2 years ago

"The problem" (or) "a possible fix" is to link against shared object libraylib.so which automatically pulls its dependent libraries via ldd BUT raylib-python-cffi/raylib/build.py is uses:

def get_the_lib_path():
    return subprocess.run(['pkg-config', '--variable=libdir', 'raylib'], text=True,
                          stdout=subprocess.PIPE).stdout.strip()

[...]
extra_link_flags = [get_the_lib_path() + '/libraylib.a', ...]

So will only link against static library installation.

If instead it were:

def get_lib_flags():
    return subprocess.run(['pkg-config', '--libs', 'raylib'], text=True,
                          stdout=subprocess.PIPE).stdout.strip().split()

[...]
        extra_link_args = get_lib_flags() + [ ...]

Then it works (and is more in the spirit of pkg-config usage). This changes the behavior such that shared object libraylib.so works but does not fix / change the behavior of the static library usage.