windows - 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.
解决方案
而不是使用use-foreign-library
,尝试加载load-foreign-library
。它是较低级别的代码,但它允许您尝试文件和路径。
还可以使用 cygcheck 找出libcurl.dll
依赖项。然后确保您已安装组件,并且它们位于PATH
.
最后,检查 libcurl.dll 在 MSYS2 中的位置。在我的系统上/c/msys64/mingw64/bin/libcurl-4.dll
推荐阅读
- python-3.x - Python 用 selenium 提取浏览器下拉列表
- pine-script - Pine Script - 如何更改先前柱的变量值?
- forms - @input 和 v-model 有什么区别?
- javascript - 如果默认选中特定单选按钮或稍后选择,则从页面中隐藏特定 H2 标签
- python - 如何在 HTML-Calendar django 中找到最近的日期
- reactjs - 无需凭据即可保护 API 路由
- typescript - 处理 Promise 执行器函数 ESLint 错误
- javascript - Konva 如何创建不相互重叠的笔触边框?
- react-native-android - 使用类组件在本机反应中将用户输入的项目添加到数组中
- javascript - 将json绑定到html并在axios中发布