You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Common Lisp构建可执行文件时GPGME异常问题求助

GPGME在Common Lisp编译可执行文件时报错:Not operational (Unspecified source)

问题描述

我正在开发一个基于Common Lisp、使用GPGME进行加密的项目,GPGME通过发行版仓库安装。以下代码在REPL中运行正常,通过命令行sbcl --load gpgme-test.lisp --eval '(main)' --eval '(exit)'执行也没问题,但用sbcl --load gpgme-test.lisp --eval "(sb-ext:save-lisp-and-die #p\"test\" :toplevel #'main :executable t)"构建可执行文件后,运行时会报错:GPGME returned error: Not operational (Unspecified source)。尝试过用Deploy构建项目,结果一致。

代码示例

(eval-when (:compile-toplevel)
  (ql:quickload :gpgme))

(require 'gpgme)

(defun main ()
  (gpgme:with-context (ctx)
    (print (gpgme:get-key ctx "<id here>"))))

解决方案

  • 显式指定GPG运行时路径:编译后的可执行文件可能无法自动定位GPG的组件路径,可在上下文初始化时明确指定gpgconf路径和密钥目录:
    (defun main ()
      (gpgme:with-context (ctx :gpgconf-path "/usr/bin/gpgconf" :homedir #p"/home/your-user/.gnupg/")
        (print (gpgme:get-key ctx "<id here>"))))
    
  • 确保gpg-agent正常运行:可执行文件启动时gpg-agent可能未自动激活,可在程序开头添加启动逻辑,或在运行可执行文件前手动执行gpg-agent --daemon。
  • 调整编译参数避免优化问题:使用save-lisp-and-die时添加:purify t参数,清理未使用代码的同时避免GPGME动态链接部分被错误处理:
    sbcl --load gpgme-test.lisp --eval "(sb-ext:save-lisp-and-die #p\"test\" :toplevel #'main :executable t :purify t)"
    
  • 检查权限设置:确保~/.gnupg目录权限为700,且可执行文件运行用户拥有该目录的读取权限。
  • 手动初始化GPGME库:在main函数开头调用初始化函数,确保库正确加载:
    (defun main ()
      (gpgme:init)
      (gpgme:with-context (ctx)
        (print (gpgme:get-key ctx "<id here>"))))
    

内容的提问来源于stack exchange,提问作者inventor500

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 02:00:14