Commits

Leonard Ritter committed 14c8075

look for library in multiple locations

Comments (0)

Files changed (1)

     global _LIB
     libname = 'SDL2'
     if IS_WIN32:
-        local_dl = os.path.join(_THISDIR, 'SDL2.dll')
+        local_dls = [
+            os.path.join(_THISDIR, 'SDL2.dll'),
+            os.path.join(os.getcwd(), 'SDL2.dll'), 
+        ]
     elif IS_LINUX:
-        local_dl = os.path.join(_THISDIR, 'libSDL2.so')
+        local_dls = [os.path.join(_THISDIR, 'libSDL2.so')]
     elif IS_DARWIN:
-        local_dl = os.path.join(_THISDIR, 'libSDL2.dylib')
+        local_dls = [os.path.join(_THISDIR, 'libSDL2.dylib')]
     else:
-        local_dl = None
+        local_dls = []
         
-    if local_dl and os.path.isfile(local_dl):
-        #print("using {0}".format(local_dl))
-        libname = local_dl 
-        
-    #import time
-    #t = time.time()
     _ffi.cdef(cdefs)
-    #print("SDL cdefs loaded in {0}s".format(time.time() - t))
-    try:
-        _LIB = _ffi.dlopen(libname)
-    except:
-        print("ERROR: unable to import SDL2")
-        traceback.print_exc()
-    return _LIB
+    
+    for dlpath in local_dls:
+        try:
+            _LIB = _ffi.dlopen(dlpath)
+            print("Loaded",dlpath)
+            return _LIB
+        except OSError:
+            pass
+        except:
+            traceback.print_exc()
+    print("ERROR: unable to find SDL2 library")
 
 def wrapstr(result):
     if result: