Mac OS X下的Mono 3.4.0 mkbundle失败

本文关键字:mkbundle 失败 Mono OS 下的 Mac | 更新日期: 2023-09-27 17:58:39

我正在尝试在MAC OS X 10.9(Mavericks)下制作静态二进制文件,这不需要mono运行时。这几乎是一台拥有最新更新和最新XCode的干净机器。

如果我不设置构建架构,我会有以下内容:

mkbundle client-patcher.exe -o client-patcher
OS is: Darwin
Sources: 1 Auto-dependencies: False
   embedding: /Users/radubalan/tmp/client-patcher.exe
Compiling:
as -o temp.o temp.s
cc -g -o client-patcher -Wall temp.c `pkg-config --cflags --libs mono-2`  temp.o
ld: warning: ignoring file /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/libmono-2.0.dylib, file was built for i386 which is not the architecture being linked (x86_64): /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/libmono-2.0.dylib
Undefined symbols for architecture x86_64:
  "_mono_main", referenced from:
      _main in temp-b1f73b.o
  "_mono_register_bundled_assemblies", referenced from:
      _mono_mkbundle_init in temp-b1f73b.o
  "_mono_set_dirs", referenced from:
      _main in temp-b1f73b.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]

如果我确实通过设置体系结构

export AS="as -arch i386"
export CC="cc -arch i386"

我得到以下信息:

mkbundle --deps --static -z client-patcher.exe -o client-patcher
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: /Users/radubalan/tmp/client-patcher.exe
   compression ratio: 40.59%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/mscorlib.dll
   compression ratio: 35.01%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll
   compression ratio: 38.06%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll
   compression ratio: 39.97%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
   compression ratio: 39.97%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll
   compression ratio: 33.85%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll
   compression ratio: 39.20%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll
   compression ratio: 35.41%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll
   compression ratio: 39.91%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Windows.Forms/4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
   compression ratio: 35.15%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
   compression ratio: 35.64%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Mono.WebBrowser/4.0.0.0__0738eb9f132ed756/Mono.WebBrowser.dll
   compression ratio: 35.01%
   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
   compression ratio: 41.03%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Accessibility/4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
   compression ratio: 29.55%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Data/4.0.0.0__b77a5c561934e089/System.Data.dll
   compression ratio: 35.13%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/Mono.Data.Tds/4.0.0.0__0738eb9f132ed756/Mono.Data.Tds.dll
   compression ratio: 38.53%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.Transactions/4.0.0.0__b77a5c561934e089/System.Transactions.dll
   compression ratio: 38.19%
   embedding: /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/gac/System.EnterpriseServices/4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
   compression ratio: 38.41%
Compiling:
as -arch i386 -o temp.o temp.s
cc -arch i386 -o client-patcher -Wall `pkg-config --cflags mono-2` temp.c -lz `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
Undefined symbols for architecture i386:
  "_CFLocaleCopyCurrent", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_CFLocaleGetIdentifier", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_CFLocaleGetValue", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_CFRelease", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_CFStringGetBytes", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_CFStringGetCString", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_CFStringGetLength", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_CFStringGetMaximumSizeForEncoding", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_class_addMethod", referenced from:
      _mono_threads_init_dead_letter in libmono-2.0.a(mono-threads-mach-helper.o)
  "_iconv", referenced from:
      _monoeg_g_iconv in libmono-2.0.a(libeglib_la-giconv.o)
     (maybe you meant: _monoeg_g_iconv_close, _monoeg_g_iconv_open , _monoeg_g_iconv )
  "_iconv_close", referenced from:
      _monoeg_g_iconv_close in libmono-2.0.a(libeglib_la-giconv.o)
      _monoeg_g_convert in libmono-2.0.a(libeglib_la-giconv.o)
     (maybe you meant: _monoeg_g_iconv_close)
  "_iconv_open", referenced from:
      _monoeg_g_iconv_open in libmono-2.0.a(libeglib_la-giconv.o)
     (maybe you meant: _monoeg_g_iconv_open)
  "_kCFLocaleCountryCode", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_kCFLocaleLanguageCode", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_kCFLocaleScriptCode", referenced from:
      _ves_icall_System_Globalization_CultureInfo_get_current_locale_name in libmono-2.0.a(libmonoruntime_la-locales.o)
  "_locale_charset", referenced from:
      _monoeg_g_get_charset in libmono-2.0.a(libeglib_la-gunicode.o)
      _monoeg_g_locale_from_utf8 in libmono-2.0.a(libeglib_la-gunicode.o)
      _monoeg_g_locale_to_utf8 in libmono-2.0.a(libeglib_la-gunicode.o)
  "_objc_allocateClassPair", referenced from:
      _mono_threads_init_dead_letter in libmono-2.0.a(mono-threads-mach-helper.o)
  "_objc_getClass", referenced from:
      _mono_threads_init_dead_letter in libmono-2.0.a(mono-threads-mach-helper.o)
  "_objc_msgSend", referenced from:
      _mono_threads_install_dead_letter in libmono-2.0.a(mono-threads-mach-helper.o)
      _mono_threads_init_dead_letter in libmono-2.0.a(mono-threads-mach-helper.o)
  "_objc_msgSendSuper", referenced from:
      _mono_dead_letter_dealloc in libmono-2.0.a(mono-threads-mach-helper.o)
  "_objc_registerClassPair", referenced from:
      _mono_threads_init_dead_letter in libmono-2.0.a(mono-threads-mach-helper.o)
  "_sel_registerName", referenced from:
      _mono_threads_init_dead_letter in libmono-2.0.a(mono-threads-mach-helper.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ERROR: [Fail]

单声道版本为:

mono --version
Mono JIT compiler version 3.4.0 ((no/d4511ef Tue Mar 25 14:35:52 EDT 2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           normal
        SIGSEGV:       altstack
        Notification:  kqueue
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          yes(3.4svn-mono-(no/e656cac)
        GC:            sgen

在Mac OS X下,是否有可能完全打破MRE独立捆绑包

在Linux(Debian)下生成了相同的捆绑包,没有任何问题。

提前谢谢!

Mac OS X下的Mono 3.4.0 mkbundle失败

要澄清,您需要在最后一个cc命令中添加以下内容:

-framework CoreFoundation -lobjc -liconv 

因此,在您的情况下,命令:

cc -arch i386 -o client-patcher -Wall pkg-config --cflags mono-2 temp.c -lz 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

应在cc:前重新写入这些标志

cc-framework CoreFoundation-lobjc-liconv-arch i386-o客户端补丁程序-Wall pkg配置--cflags mono-2 temp.c-lz pkg配置--libs-only-L mono-2 pkg配置--variable=libdir mono-2/libmono-2.0.a pkg配置--librs-only-L mono-2|sed-e"s/-lmono-2.0//"temp.o

只需剪切/粘贴最后一个cc命令,将这些标志添加到其中,剪切/粘贴回终端,点击回车即可享受。

您需要将二进制文件与CoreFoundation框架链接起来。根据Mono 3.4的发行说明,这是Mono 3.4最近的一次更改。不久前也报道了类似的问题。