首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从C#应用程序调用Clojure静态方法

无法从C#应用程序调用Clojure静态方法
EN

Stack Overflow用户
提问于 2011-12-20 05:36:30
回答 1查看 833关注 0票数 3

我得到异常(非静态字段、方法或…)需要对象引用

以下是我想做的事:

代码语言:javascript
复制
;; Here's the program.clj file from a VsClojure project.
;; First thing you need to do is add the :methods property
;; which takes a of methods that are to be generated when
;; the class is created.  Here, I'm generating a static method
;; named hi which has no parameters and returns a String.
;;
;; When program.hi() is called from the C# code the
;; the clojure function -hi will be called.  By default any
;; method in the :methods vector will be mapped to a function
;; with the same name prefixed by a -.  
(ns program
  (:gen-class
   :methods [ #^{:static true} [hi [] String]]))

(defn -hi []
  "Hi from ClojureCLR!")

(defn -main [& args]
  (println "Hello world")
  (println (-hi)))

;; The C# code is nothing special
;; You MUST add both the program.exe and program.clj.dll
;; files as references in hte C# project.  In addition
;; to these assemblies you'll need to add the following
;; assemblies which can be found in the ClojureCLR's directory:
;; clj.gen_class.clj.dll, clojure.clr.io.clj.dll, clojure.core.clj.dll
;; clojure.core_deftype.clj.dll, clojure.core_printl.clj.dll,
;; clojure.core_proxy.clj.dll, clojure.genclass.clj.dll, clojure.gvec.clj.dll


;; using System;

;; namespace csharp
;; {
;;    class Program
;;    {
;;        static void Main(string[] args)
;;        {
;;    // You can see here you'd never know this was
;;    // really a clojure function I'm calling
;;          Console.WriteLine("p.hi => {0}", program.hi());
;;        }
;;    }
;;}

但got:错误1非静态字段、方法或属性'program.hi()‘ConsoleApplication1.需要对象引用。

和我在这里的一样:https://github.com/nCdy/clojure-clr-intro/blob/master/3-calling-clojure-from-c-sharp/csharp/clj_in_csharp/Program.cs

我使用的是内置的Visual扩展vsClojure。1.1.0;GitHub自述文件之后的最新版本1.1.0。也许我需要更新它,但我有一些小的局部问题,这使我不能建立最后的clojre(我将在明年解决它们)。

因此,问题是我如何从C#调用call库,我的麻烦在哪里?

日志:

代码语言:javascript
复制
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\program.exe', Symbols loaded.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\Clojure.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\Microsoft.Scripting.ExtensionAttribute.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_ru_b77a5c561934e089\mscorlib.resources.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-20 12:29:14

在c#项目中,您有program.exe和program.clj.dll的引用吗?

如果您自己构建了clojure项目并运行它,那么它对您有用吗?

您可以尝试的另一件事是在https://github.com/downloads/richhickey/clojure-clr/clojure-clr-1.3.0-Debug-4.0.zip上获得最新的二进制构建。一旦您得到该设置,请执行以下操作:

  1. 在program.clj所在的目录中运行clojure.compile程序。
  2. 将步骤1的输出中的program.exe和program.clj.dll添加到C#项目中。
  3. 构建C#项目.

那应该管用。我已经构建了vs clojure和上面我向您展示的方式。我用的是clojureclr 1.3

希望这能帮上忙,罗伯

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8571242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档