【问题标题】:Can't set CLOJURE_LOAD_PATH; getting TypeInitializationError from runtime无法设置 CLOJURE_LOAD_PATH;从运行时获取 TypeInitializationError
【发布时间】:2012-01-05 14:40:26
【问题描述】:

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

在program.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”。我的理解是运行时查看加载路径的环境变量。那为什么找不到呢?还怎么设置加载路径?

【问题讨论】:

    标签: clojure clojureclr


    【解决方案1】:

    丹,

    您需要将以下与 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`
    

    一旦你拥有了那些你将包含的程序集,你就可以运行棒球.exe。如果你还没有我,你可以看看这篇博文:http://www.myclojureadventure.com/2011/12/intro-to-clojure-clr-calling-clojure.html我遇到了你之前遇到的同样的问题,这就是促使这篇文章的原因。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-11-08
        • 1970-01-01
        • 2012-07-22
        • 1970-01-01
        • 2021-01-16
        • 2016-09-12
        • 1970-01-01
        相关资源
        最近更新 更多