尝试在 NixOS 中运行 Clojure 项目时加载共享库时出错

Error loading a shared library when trying to run a Clojure project in NixOS

提问人:Jeff 提问时间:9/5/2023 更新时间:10/6/2023 访问量:34

问:

我正在尝试在 NixOS 23.05 中运行一个超级简单的 Clojure 项目。

该文件包含:project.clj

(defproject fsm "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.11.1"]
                 [com.phronemophobic/clj-graphviz "0.6.1"]]
  :main ^:skip-aot fsm.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all
                       :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})

该文件包含:src/fsm/core.clj

(ns fsm.core
  (:gen-class))

(require '[com.phronemophobic.clj-graphviz :refer [render-graph]])

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!")

  (render-graph {:edges [["a" "b"]]})
  ;; writes to graph.png

  (render-graph {:edges [["a" "b"]]}
                {:filename "my-graph.png"}))

但是当我输入时,我收到错误消息:lein run

Execution error (UnsatisfiedLinkError) at com.sun.jna.NativeLibrary/loadLibrary (NativeLibrary.java:323).
Unable to load library 'gvc':
libgvc.so: cannot open shared object file: No such file or directory
libgvc.so: cannot open shared object file: No such file or directory
Native library (linux-x86-64/libgvc.so) not found in resource path (...)

这在其他 Linux 发行版(Pop OS!/Ubuntu)中工作正常,所以我相信我缺少 NixOS 配置。我不熟悉这个发行版。

Clojure Leiningen Nixos

评论


答:

0赞 E.T. 10/6/2023 #1

libgvc.so是 GraphViz 的一部分。您需要安装 GraphViz 才能访问该库。随心所欲地这样做。

如果你不使用 Flakes 来部署/运行你的应用,安装 GraphViz 的最简单方法是使用 Nix shell,如下所示:

$ nix-shell -p graphviz
$ lein run

您也可以像安装相同的方式将 添加到已安装的软件包列表中。graphvizlein