首页 > 解决方案 > Unable to use libcurl with cffi on Windows 10

问题描述

I am playing with the CFFI tutorial on Windows 10 and have installed the libcurl-devel package using msys2. I found a file libcurl.dll.a in the directory c:\msys2\usr\lib\ and added this directory to *foreign-library-directories* using:

(pushnew #P"c:/msys64/usr/lib/" *foreign-library-directories*
         :test #'equal)

But if I try (use-foreign-library libcurl) I get the following error:

Unable to load foreign library (LIBCURL).
  Error opening shared object "libcurl.dll"

What am I missing? I tried to point to libcurl.dll.a directly but the error stays the same:

(define-foreign-library libcurl
      (:darwin (:or "libcurl.3.dylib" "libcurl.dylib"))
      (:unix (:or "libcurl.so.3" "libcurl.so"))
      (t "libcurl.dll.a"))

Here is the complete code as given in the tutorial:

(asdf:load-system :cffi)

 ;;; Nothing special about the "CFFI-USER" package.  We're just
 ;;; using it as a substitute for your own CL package.
(defpackage :cffi-user
  (:use :common-lisp :cffi))

(in-package :cffi-user)

(pushnew #P"c:/msys64/usr/lib/" *foreign-library-directories*
         :test #'equal)

(define-foreign-library libcurl
  (:darwin (:or "libcurl.3.dylib" "libcurl.dylib"))
  (:unix (:or "libcurl.so.3" "libcurl.so"))
  (t (:default "libcurl")))

(use-foreign-library libcurl)

EDIT

I am using SBCL 1.4.16 from the portacle package.

EDIT 2

Just for the sake of completeness. If I change define-foreign-library to

(define-foreign-library libcurl
  (:darwin (:or "libcurl.3.dylib" "libcurl.dylib"))
  (:unix (:or "libcurl.so.3" "libcurl.so"))
  (t "libcurl.dll.a"))

the errors changes:

Unable to load foreign library (LIBCURL).
  Error opening shared object "c:\\msys64\\usr\\lib\\libcurl.dll.a":
 %1 ist keine zulässige Win32-Anwendung.

As far as I understand at least the file is found but seems not to be in the right format. I didn't find any further information about the difference between dynamic (.dll) and static (.dll.a) files with respect to cffi and don't have the resources at the moment to further investigate this.

标签: windowscommon-lispmsys2cffi

解决方案


而不是使用use-foreign-library,尝试加载load-foreign-library。它是较低级别的代码,但它允许您尝试文件和路径。

还可以使用 cygcheck 找出libcurl.dll依赖项。然后确保您已安装组件,并且它们位于PATH.

最后,检查 libcurl.dll 在 MSYS2 中的位置。在我的系统上/c/msys64/mingw64/bin/libcurl-4.dll


推荐阅读