Page 1 of 1

Trouble loading some libraries using CFFI

Posted: Sat Oct 29, 2011 1:58 pm
by virex
Dear Lispers,

I seem to have run across a little problem with importing external libraries, which can most easily be seen from the following session:

Code: Select all

CL-USER> (probe-file "./lib/SDL.dll")
#P"c:/Programming/Projects/lisp/BloodTV/lib/SDL.dll"
CL-USER> (CFFI:load-foreign-library *)
#<CFFI:FOREIGN-LIBRARY #xCC375B6>
CL-USER> (probe-file "./lib/SDL_ttf.dll")
#P"c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll"
CL-USER> (CFFI:load-foreign-library *)
; Evaluation aborted on #<CFFI:LOAD-FOREIGN-LIBRARY-ERROR #xCBEB8FE>.
That last one terminates with the error:

Code: Select all

Unable to load foreign library (LIBRARY-142).
  Error opening shared library c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll : Kan opgegeven module niet vinden. .
   [Condition of type CFFI:LOAD-FOREIGN-LIBRARY-ERROR]

Backtrace:
  0: (CFFI::FL-ERROR "Unable to load foreign library (~A).~%  ~A" #:LIBRARY-142 "Error opening shared library c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll : Kan opgegeven module niet vinden. .")
      Locals:
        CFFI::CONTROL = "Unable to load foreign library (~A).~%  ~A"
        CFFI::ARGUMENTS = (#:LIBRARY-142 ..))
  1: ((:INTERNAL CFFI::%DO-LOAD CFFI::%DO-LOAD-FOREIGN-LIBRARY) #<CFFI:FOREIGN-LIBRARY #xCC771C6> #:LIBRARY-142 #P"c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll")
      Locals:
        CFFI::LIB = #<CFFI:FOREIGN-LIBRARY #xCBF7866>
        CFFI::NAME = #:LIBRARY-142
        CFFI::SPEC = #P"c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll"
  2: (CFFI:LOAD-FOREIGN-LIBRARY #P"c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll" :SEARCH-PATH NIL)
      Locals:
        CFFI::LIBRARY = #P"c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll"
        CFFI::SEARCH-PATH = NIL
        #:USE-VALUE = #<RESTART USE-VALUE #x3BCF8AE>
        #:RETRY = #<RESTART CFFI::RETRY #x3BCF886>
        #:G8388 = (#<RESTART CFFI::RETRY #x3BCF886> #<RESTART USE-VALUE #x3BCF8AE>)
        CCL::%RESTARTS% = ((#<RESTART CFFI::RETRY #x3BCF886> #<RESTART USE-VALUE #x3BCF8AE>) ..)))
  3: (CCL::CALL-CHECK-REGS CFFI:LOAD-FOREIGN-LIBRARY #P"c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll")
      Locals:
        CCL::FN = CFFI:LOAD-FOREIGN-LIBRARY
        CCL::ARGS = (#P"c:/Programming/Projects/lisp/BloodTV/lib/SDL_ttf.dll")
        CCL::OLD-REGS = NIL
  4: (CCL::CHEAP-EVAL (CFFI:LOAD-FOREIGN-LIBRARY *))
      Locals:
        CCL::FORM = (CFFI:LOAD-FOREIGN-LIBRARY *)
        CCL::*NX-SOURCE-NOTE-MAP* = NIL
  5: (SWANK::EVAL-REGION "(CFFI:load-foreign-library *)\n")
      Locals:
        STRING = "(CFFI:load-foreign-library *)\n"
        STREAM = #<STRING-INPUT-STREAM  #xCBF79CE>
        VALUES = NIL
        - = (CFFI:LOAD-FOREIGN-LIBRARY *)
        SWANK::FORM = (CFFI:LOAD-FOREIGN-LIBRARY *)
  6: ((:INTERNAL SWANK::REPL-EVAL))
      Locals:
        STRING = "(CFFI:load-foreign-library *)\n"
Basically I'm stumped. It should be perfectly capable of finding the file, but it doesn't?

Re: Trouble loading some libraries using CFFI

Posted: Sat Oct 29, 2011 11:11 pm
by ramarren
I'm guessing that the issue is that SDL_ttf depends on Freetype. If you are not going to place the libraries somewhere where the system can find them itself, then you need to specify a pathname to all libraries and their dependencies.

Re: Trouble loading some libraries using CFFI

Posted: Sun Oct 30, 2011 1:18 pm
by virex
So I should load the Freetype library first?

Re: Trouble loading some libraries using CFFI

Posted: Mon Oct 31, 2011 6:41 pm
by nuntius
Based on your first code snippet, it appears that PROBE-FILE is incorrectly returning an invalid path.

Which implementation is this? I'd try posting that directly to one of their support lists. It may be fixed in a newer version, or it may be a good bug report.

Re: Trouble loading some libraries using CFFI

Posted: Tue Nov 01, 2011 11:56 am
by virex
The behavior is the same under CCL 1.6 (the version I posted) and the version of SBCL I have (0.9.8.1? Most recent stable windows build as of June, IIRC). However, Ramarren seems to have nailed it, I need to load libfreetype-6.dll before loading sdl-ttf.dll. Now I just need to figure out in what order to load all the other libraries and I'm set :)