我得到异常(非静态字段、方法或…)需要对象引用
以下是我想做的事:
;; 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.需要对象引用。
我使用的是内置的Visual扩展vsClojure。1.1.0;GitHub自述文件之后的最新版本1.1.0。也许我需要更新它,但我有一些小的局部问题,这使我不能建立最后的clojre(我将在明年解决它们)。
因此,问题是我如何从C#调用call库,我的麻烦在哪里?
日志:
'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.发布于 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上获得最新的二进制构建。一旦您得到该设置,请执行以下操作:
那应该管用。我已经构建了vs clojure和上面我向您展示的方式。我用的是clojureclr 1.3
希望这能帮上忙,罗伯
https://stackoverflow.com/questions/8571242
复制相似问题