rpav / cl-cairo2

Cairo bindings for Common Lisp
https://github.com/rpav/cl-cairo2/wiki
Boost Software License 1.0
62 stars 15 forks source link

libcairo-2.dll will not load on Windows 8 #15

Closed ezrarush closed 10 years ago

ezrarush commented 10 years ago

Using SBCL on Windows 8.1 64-bit with a 32-bit libcairo-2.dll installed from latest gtk+3 I cannot quickload cl-cairo2 with the following error in slime

Unable to load foreign library (LIBCAIRO).
  Error opening shared object "libcairo-2.dll":
 The specified module could not be found.
   [Condition of type CFFI:LOAD-FOREIGN-LIBRARY-ERROR]

I have installed libcairo-2.dll in C:\windows\SysWOW64 to receive the error message in slime.

I have also tried to install the experimental 64-bit version of libcairo-2.dll downloaded from cairographics.org in C:\windows\system32 with the same error message in slime.

When I try to do all of this directly in SBCL console I get the same error message.

When I put the 32-bit libcairo-2.dll in C:\windows\system32 (which is the place for 64-bit dlls) I get a new error msg

Unable to load foreign library (LIBCAIRO).
  Error opening shared object "libcairo-2.dll":
 %1 is not a valid Win32 application.
   [Condition of type CFFI:LOAD-FOREIGN-LIBRARY-ERROR]

When I add C:\gtk\bin which contains said 32-bit dll to my system path I get this new error message again (This should work as I believe this is the correct way to install dlls and c programs do in fact find and use the dll this way).

I can compile cairo code in c using mingw gcc and run it using the 32-bit libcairo-2.dll. If i remove the 32-bit dll the program complains there is no libcairo-2.dll until I put it back in the system path (e.i C:\gtk\bin). cairo works on the system just not cl-cairo2.

I realize it might be a problem with cffi.

rpav commented 10 years ago

Have you tried putting this in the same directory as SBCL? I think this is what I had to do.

ezrarush commented 10 years ago

thank you for replying. Your comment helped me figure out why I was having so much trouble.

It was misleading error messages form cffi:load-foreign-library-error. You see if I correctly load the first DLL in a series of required DLLs but the second DLL gives an error; cffi's error displays the first dll as the malfunctioning DLL.

example: cl-cairo need libcairo-2.dll, libfontconfig-1.dll. If 64-bit libcairo-2.dll is correct and loads but libfontconfig-1.dll is not correct (maybe because it is 32-bit) it still gives the following error message

Unable to load foreign library (LIBCAIRO).
  Error opening shared object "libcairo-2.dll":
 %1 is not a valid Win32 application.
   [Condition of type CFFI:LOAD-FOREIGN-LIBRARY-ERROR]

Also slime does not display windows pop-up error messages but SBCL console does.

edit: cl-cairo2 loads using a 64-bit SBCL with 64-bit DLLs on 64-bit Windows 8.1 just fine no problems. http://win32builder.gnome.org/gtk+-bundle_3.10.4-20131202_win64.zip contains the complete set of correct DLLs.

rpav commented 10 years ago

Yeah this is more of an SBCL/CFFI/Windows issue, but saying such doesn't really solve the problem. Unfortunately I have also heard reports of issues with 32-bit Cairo (and SBCL?) as well. You may want to try CCL; I think the Windows support is a bit more active there. I've also had fewer issues with foreign code in CCL recently.

ezrarush commented 10 years ago

I will report back if this issue is still active later with my progress. I wish to make lisp programs that run on 64-bit windows 8 even if the lisp program is itself 32-bit so these issues are important to me

ezrarush commented 10 years ago

To install the 32-bit cairo DLLs please use this official tutorial (cairo is now part of gtk+)

http://www.gtk.org/download/win32_tutorial.php

rpav commented 10 years ago

I will check this out; have you tried with CCL and 64-bit cairo?

For 32-bit, I would expect a complete set of 32-bit libraries would be required. However I don't like the fact that 64-bit doesn't work. I'll look into it next time I get a chance to boot over and do some work there.

ezrarush commented 10 years ago

my opinion is that gtk+ made a mistake in one of their 64-bit DLLs (namely libpng14-14.dll) and this is not cl-cairo2's fault.

Also my opinion is that if the lisp image is 64-bit cffi demands that every foreign function be 64-bit and will not handle any 32-bit DLLs or WoW64. this is not cl-cairo2's fault unless there is some config i missed.

rpav commented 10 years ago

WRT 64-bit vs 32-bit, this is almost certainly the case. I recall back in the 32/16-bit days, there were ways to making "thunking" calls into 16-bit code from 32-bit; this required special handling and was pretty painful. I'm pretty sure you can't call 32-bit code from 64 from what I know of the ABI.

As for the broken DLL, if I can confirm this I'll file a bug report or similar and see if we can get a fixed version.

ezrarush commented 10 years ago

I was wrong about gtk.org having bad DLLs. My SBCL wasn't loading libpng14-14.dll for some reason I cannot explain.

http://www.gtk.org/download/win64.php has working DLLs but not all that are required for cl-cairo2 (the link is missing liblzma-5.dll)

http://win32builder.gnome.org/gtk+-bundle_3.10.4-20131202_win64.zip has all the DLLs necessary to load cl-cairo2

as for cffi running on a 64-bit lisp image not being able to handle wow64 32-bit DLLS, i guess i can understand.

ezrarush commented 10 years ago

Thank you for helping me. I have installed SBCL 1.2.1 AMD64 and quickloaded cl-cairo2.

There is nothing wrong with the DLLs on http://www.gtk.org/download/win64.php I have compiled a 64-bit c language cairo2 windows executable using mingw-w64 and it uses the DLLs just fine. I was wrong and I do not know why my SBCL 1.1.8 AMD64 couldn't load cl-cairo2 with missing DLL errors.

If anyone needs the complete set of DLLs (both 32 and 64 bit) to run cl-cairo2 on windows please download them form this link http://win32builder.gnome.org/