2014-11-21 53 views
4

在新安裝後試用Mono中的hello world示例。試過GTK例子如[​​指示:OSx單聲道gtk問候世界。 Gtk.Container引發了一個例外

mcs hello.cs -pkg:gtk-sharp-2.0 
mono hello.exe 

,我得到這個:

> 2014-11-21 21:45:29.629 mono[45107:1731007] *** WARNING: Method 
> userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. 
> It should not be used in new applications. Use convertRectToBacking: 
> instead. 
> 
> Unhandled Exception: System.TypeInitializationException: An exception 
> was thrown by the type initializer for Gtk.Container ---> 
> System.DllNotFoundException: gtksharpglue-2 at (wrapper 
> managed-to-native) 
> Gtk.Container:gtksharp_gtk_container_get_focus_child_offset() at 
> Gtk.Container..cctor() [0x00000] in <filename unknown>:0 --- End 
> of inner exception stack trace --- at Gtk.Bin..ctor (IntPtr raw) 
> [0x00000] in <filename unknown>:0 at Gtk.Window..ctor (WindowType 
> type) [0x00000] in <filename unknown>:0 at Gtk.Window..ctor 
> (System.String title) [0x00000] in <filename unknown>:0 at 
> Hello.Main() [0x00000] in <filename unknown>:0 [ERROR] FATAL 
> UNHANDLED EXCEPTION: System.TypeInitializationException: An exception 
> was thrown by the type initializer for Gtk.Container ---> 
> System.DllNotFoundException: gtksharpglue-2 at (wrapper 
> managed-to-native) 
> Gtk.Container:gtksharp_gtk_container_get_focus_child_offset() at 
> Gtk.Container..cctor() [0x00000] in <filename unknown>:0 --- End 
> of inner exception stack trace --- at Gtk.Bin..ctor (IntPtr raw) 
> [0x00000] in <filename unknown>:0 
> at Gtk.Window..ctor (WindowType type) [0x00000] in <filename 
> unknown>:0 
>  at Gtk.Window..ctor (System.String title) [0x00000] in <filename unknown>:0 
>  at Hello.Main() [0x00000] in <filename unknown>:0 

任何想法是什麼引起的呢?

回答

0

Jonathan Pryor在Xamarin forum中很好地回答了這個問題。這些位從他的答案幫助我:

您不導出$ DYLD_LIBRARY_PATH或$ DYLD_FALLBACK_LIBRARY_PATH,以便它可以找到。

...

的問題是,libgtk-石英2.0.0.dylib無法找到,因爲它安裝到/Library/Frameworks/Mono.framework/Libraries,而不是/ usr/lib目錄(或全球任何東西)。

運行在你的shell下面第一,其後mono hello.exe應該工作:

export DYLD_FALLBACK_LIBRARY_PATH=/Library/Frameworks/Mono.framework/Versions/Current/lib:/lib:/usr/lib 
+0

請注意,喬納森建議創建一個腳本(見下文)。我的經驗是OS X在涉及DYLD變量的環境變化方面表現不佳。 – 2015-09-15 20:46:58

0

第一個錯誤信息,

「userSpaceScaleFactor類的NSView是在10.7及更高版本棄用」

可以被GTK的用戶忽略。但是,GTK開發人員社區必須在蘋果刪除引用的調用之前更新其代碼。

Apple Dev Community Notices re userSpaceScaleFactor

的腳本來隔離第二個問題。不要忘記chmod + x它。

#!/bin/zsh 
export DYLD_FALLBACK_LIBRARY_PATH=/Library/Frameworks/Mono.framework/Versions/Current/lib:/lib:/usr/lib 

mono $1.exe