Mono 3.4.0 mkbundle under Mac OS X failed

2019-02-26 03:35发布

问题:

I`m trying to make static binary under MAC OS X 10.9 (Mavericks) which is not require mono runtime. This is almost clean machine with the latest updates and the latest XCode.

If I do not set the build architecture, I have the following:

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]

If I do set architecture by

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

I`m getting the following:

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 is:

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

Is the possibility to make MRE-independent bundle completely broken under Mac OS X?

The same bundle under Linux (Debian) is produced without any problems.

Thank you in advance!

回答1:

To clarify, you need to add the following to that last cc command:

-framework CoreFoundation -lobjc -liconv 

So in your case the command:

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

Should be re-written with those flags in front of cc:

cc -framework CoreFoundation -lobjc -liconv -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

Simply cut/paste that last cc command, add those flags to it, cut/paste back into the terminal, hit enter and enjoy.



回答2:

You need to link the binary with the CoreFoundation framework. This is a recent change in Mono 3.4 as per the Mono 3.4 release notes. A similar issue was reported a while ago.