无法设置CLOJURE_LOAD_PATH;从运行时获取类型初始化错误



我试图在CLR上运行Clojure,但遇到了一些基本问题。基于这个问题,我使用以下代码:

在程序.clj:

(ns program
  (:require [clojure.core])
  (:gen-class
   :methods [#^{:static true} [output [int int] int]]))
(defn output [a b]
  (+ a b))
(defn -output [a b]
  (output a b))
(defn -main []
  (println (str "(+ 5 10): " (output 5 10))))

然后在Program.cs:中

using System;
using clojure.lang;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            program p = new program();
            System.Console.WriteLine(p.output(5, 9));
            System.Console.ReadLine();
        }
    }
}

当我运行Program.cs时,它会抛出一个TypeInitializationError,并显示错误消息"在加载路径上找不到clojure/core.clj.dll或clojure/core.clj"。为了调试,我添加了以下行:

System.Environment.SetEnvironmentVariable("clojure.load.path", "c:clojure");
System.Console.WriteLine(System.Environment.GetEnvironmentVariable("clojure.load.path"));
System.Console.WriteLine(RT.CLOJURE_LOAD_PATH);

正如我所期望的,第一个WriteLine显示"c:\clojure"。第二个显示了"clojure.load.path"。我的理解是运行时会查找加载路径的环境变量。为什么它找不到呢?如何设置加载路径?

Dan,

你需要在你的项目中包括以下与clojureclr相关的dll:

`Clojure.dll,
clojure.clr.io.clj.dll,
clojure.core.clj.dll,
clojure.core.protocols.clj.dll,
clojure.core_clr.clj.dll,
clojure.core_deftype.clj.dll,
clojure.core_print.clj.dll,
clojure.core_proxy.clj.dll,
clojure.genclass.clj.dll,
clojure.gvec.clj.dll`

一旦你有了这些程序集,你就可以运行baseball.exe了。如果你还没有,我可以看看这篇博客文章:http://www.myclojureadventure.com/2011/12/intro-to-clojure-clr-calling-clojure.html我遇到了你之前遇到的同样的问题,这就是为什么我发了这个帖子。

我对Clojure/CLR了解不多,但我不会认为在加载Clojure运行时后更改环境变量会更改Clojure加载路径。它在Clojure/JVM中的工作方式肯定不是这样的——这些类型的环境var->系统设置显然是在加载主代码后修复的。在Clojure/JVM中,这通常意味着您从另一个已经为您设置了加载路径的进程(通常是直接启动JVM的批处理脚本或leiningen/cake调用)启动主Clojure进程。

最新更新