2014-06-23 70 views
1

我已經在這,現在幾天,雖然我很快設法Mono的mkbundle建立在Windows和Linux本地可執行我一直沒能做到爲OS XMkbundle未能在OS X編寫C#應用程序

我使用的是單聲道相同的3.4.0,因爲我需要.NET 4.5的支持,並能夠編譯x86_64的在OS X將是很好過。

我目前使用下面這個簡單的bash腳本來嘗試mkbundle編譯:

#!/bin/bash 
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/pkgconfig 
#PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/pkgconfig 

mkbundle bin/Release/Launcher.exe --static --deps -o bin/Release/OSXNative/Launcher.exe 

我得到了以下的輸出:

$ ./OSXNativeBuild.sh 
OS is: Darwin 
Note that statically linking the LGPL Mono runtime has more licensing restrictions than dynamically linking. 
See http://www.mono-project.com/Licensing for details on licensing. 
Sources: 1 Auto-dependencies: True 
    embedding: /Volumes/app/Launcher/Launcher/bin/Release/Launcher.exe 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/mscorlib.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Windows.Forms/4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Mono.WebBrowser/4.0.0.0__0738eb9f132ed756/Mono.WebBrowser.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Runtime.Serialization.Formatters.Soap/4.0.0.0__b03f5f7f11d50a3a/System.Runtime.Serialization.Formatters.Soap.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Accessibility/4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Data/4.0.0.0__b77a5c561934e089/System.Data.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Mono.Data.Tds/4.0.0.0__0738eb9f132ed756/Mono.Data.Tds.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Transactions/4.0.0.0__b77a5c561934e089/System.Transactions.dll 
    embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.EnterpriseServices/4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll 

Compiling: 
as -o temp.o temp.s 
cc -o bin/Release/OSXNative/Launcher.exe -Wall `pkg-config --cflags mono-2` temp.c `pkg-config --libs-only-L mono-2` `pkg-config --variable=libdir mono-2`/libmono-2.0.a `pkg-config --libs-only-l mono-2 | sed -e "s/\-lmono-2.0 //"` temp.o 
ld: warning: ignoring file /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/pkgconfig/../../lib/libmono-2.0.a, file was built for archive which is not the architecture being linked (x86_64): /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/pkgconfig/../../lib/libmono-2.0.a 
Undefined symbols for architecture x86_64: 
    "_mono_main", referenced from: 
     _main in temp-I71V1m.o 
    "_mono_register_bundled_assemblies", referenced from: 
     _mono_mkbundle_init in temp-I71V1m.o 
    "_mono_set_dirs", referenced from: 
     _main in temp-I71V1m.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
ERROR: [Fail] 

事情我已經嘗試:

  • 我發現刪除--static參數允許mkbundle構建成功。但是,這只是上面的問題,以運行時,我希望它靜態編譯。
  • Mono 3.4.0 release notes提到Mac OS X上的mkbundle現在必須始終鏈接到Objective-C運行時。然而,我無法弄清楚如何去做,爲什麼我想這麼做對我來說沒有任何意義。

回答

6

我研究了最後的問題 - 我看到了新的mkbundle屬性需求和一些不匹配的體系結構設置。下面的腳本爲我工作:

#!/bin/bash 

# Notes: 
# You will need the Mono SDK 3.x series as the 2.x SDK cannot build for 64bit architectures. 
# It appears that Mono 3.x still cannot compile for 64bit without having to manually compile Mono yourself. 
# Since we don't strictly need 64bit support the below forces a 32bit build. 

# Ensure it can find pkg-config: 
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/pkgconfig 

# Force 32bit build and manually set some clang linker properties: 
export AS="as -arch i386" 
export CC="cc -arch i386 -lobjc -liconv -framework Foundation" 

# Build: 
mkbundle bin/Release/Launcher.exe --static --deps -o bin/Release/OSXNative/Launcher.exe 
+0

http://www.mono-project.com/Mono:OSX很顯然,64位單聲道的OS X是仍在進行中,但尚未投入生產。因此,就像你發現的那樣,切換到32位是一種解決方法。 –

+0

'切換到32位'根本不是工作。 Mono 3中的mkbundle需要額外的參數才能正確構建,如上面的腳本。除最新發行說明中的​​簡短說明外,此處不記載任何內容。 :/ –