78344

Compiling mono as static library

Question:

I want to compile libmono as static library at Windows.

Target platform is Windows x86. Build environment: Windows 7 64-bit, VC++ Express 2010

What i have already done.

1) Downloaded mono 2.10.8 sources.<br /> 2) Opened mono.sln from msvc folder and ensured that everything is compilling.<br /> 3) Then i've made some changes:<br /> 3.1) General->Project Defaults->Configuration Type: Static library (.lib)<br /> 3.2) General->Project Defaults->Use of MFC: Use Standard Windows Libraries<br /> 3.3) C/C++->Code Generation->Runtime Library: Multi-threaded (/MT)<br /> 4) Built it and VC++ 2010 successfully created mono-2.0.lib<br /> 5) Added it in linker inputs of my own project (that i want to embed mono in) with:<br /> 5.1) General->Project Defaults->Configuration Type: Application (.exe)<br /> 5.2) General->Project Defaults->Use of MFC: Use MFC in a Ststic Library<br /> 5.3) C/C++->Code Generation->Runtime Library: Multi-threaded (/MT)

It seems to work near perfect but with some terrible issues: <a href="https://stackoverflow.com/questions/10717406/mysterious-behavior-of-dictionarytkey-tsource" rel="nofollow">Mysterious behavior of Dictionary<TKey, TSource></a>

Is everything done correct? Should i specify any other compiler options or preprocessor directives?

<strong>P.S.:</strong> libmono command line is:

<blockquote>

/I"..\libgc\include" /I"..\" /I"..\mono\" /I"..\mono\jit" /I"..\mono\eglib\src" /I"....\mono\eglib\src" /I"..\eglib\src" /Zi /nologo /W1 /WX- /O1 /Ob1 /Oi /Oy- /D "NDEBUG" /D "<strong>i386</strong>" /D "TARGET_X86" /D "i386" /D "WIN32" /D "_WIN32" /D "<strong>WIN32</strong>" /D "_WINDOWS" /D "WINDOWS" /D "HOST_WIN32" /D "TARGET_WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "GC_NOT_DLL" /D "HAVE_CONFIG_H" /D "WINVER=0x0500" /D "_WIN32_WINNT=0x0500" /D "_WIN32_IE=0x0501" /D "WIN32_THREADS" /D "FD_SETSIZE=1024" /D "<strong>default_codegen</strong>" /D "MONO_ASSEMBLIES=0" /D "_UNICODE" /D "UNICODE" /GF /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fp".\Release/libmono.pch" /Fa"Win32\obj\libmono\" /Fo"Win32\obj\libmono\" /Fd"Win32\obj\libmono\vc100.pdb" /Gd /TC /analyze- /errorReport:queue

</blockquote>

<strong>UPD:</strong>

I've found this discussion which is related to my question <a href="http://mono.1490590.n4.nabble.com/Mono-static-library-td3546774.html" rel="nofollow">http://mono.1490590.n4.nabble.com/Mono-static-library-td3546774.html</a>

Is it still actual? Can i use SGen instead of Boehm? If yes, any tip is very appreciated. And if yes, can i then use mono as a static library with use of sgen?

Answer1:

I'm going to skip the details of your question because I suspect an <a href="https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem" rel="nofollow">XY problem</a>.

If you want to create an application that is statically linked to the mono runtime, just use mkbundle.exe:

mcs Main.cs mkbundle --static --deps -z Main.exe -o Main ldd Main

results in

sehe@mint12:~/Projects/SODemo/SODemo$ mkbundle --static --deps -z Main.exe -o Main OS is: Linux 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: /home/sehe/Projects/SODemo/SODemo/Main.exe compression ratio: 44,62% embedding: /usr/lib/mono/4.0/mscorlib.dll compression ratio: 34,99% embedding: /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll compression ratio: 37,49% embedding: /usr/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll compression ratio: 40,12% embedding: /usr/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll compression ratio: 40,12% embedding: /usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll compression ratio: 34,06% embedding: /usr/lib/mono/gac/System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll compression ratio: 39,32% embedding: /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll compression ratio: 34,16% embedding: /usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll compression ratio: 40,01% Compiling: as -o temp.o temp.s cc -o Main -Wall `pkg-config --cflags mono-2` temp.c -lz `pkg-config --libs-only-L mono-2` -Wl,-Bstatic -lmono-2.0 -Wl,-Bdynamic `pkg-config --libs-only-l mono-2 | sed -e "s/\-lmono-2.0 //"` temp.o Done sehe@mint12:~/Projects/SODemo/SODemo$ ldd Main linux-vdso.so.1 => (0x00007fff7b1ff000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ffe95d0f000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffe95a8b000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ffe95882000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ffe9567e000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ffe95461000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffe950bf000) /lib64/ld-linux-x86-64.so.2 (0x00007ffe95f52000)

<strong>Note</strong> the resulting executable size is: 5.8Mb for a trivial program. But it <em>is</em> completely independent.

See also

<ul><li>

Monotouch linker <a href="http://docs.xamarin.com/ios/advanced_topics/linker" rel="nofollow">http://docs.xamarin.com/ios/advanced_topics/linker</a> This optimizes all unused references

</li> <li>

Sebastian Poulliot's blog <a href="http://spouliot.wordpress.com/" rel="nofollow">http://spouliot.wordpress.com/</a>

</li> </ul>

Answer2:

All is clear for me now.

Hans Passant gave an answer to <a href="https://stackoverflow.com/questions/10717406/mysterious-behavior-of-dictionarytkey-tsource" rel="nofollow">Mysterious behavior of Dictionary<TKey, TSource></a> that shows that static linking won't work.

Answer to this question shows that there are no possibilities to choose another GC yet: <a href="https://stackoverflow.com/questions/8214594/compiling-mono-from-visual-studio-with-sgen-support" rel="nofollow">Compiling Mono from Visual Studio with sgen support</a>

Summarizing, it's understood that nowdays the only solution on windows is dynamic linking

Recommend

  • undefined reference to `_imp___ZN10HTTPClient5abortEv' and others
  • How can I assert from Python C code?
  • Standard #ifdef for Cygwin
  • Unit test for a C program
  • Winsock accept() returning WSAENOTSOCK (code 10038)
  • Pass str as an int array to a Python C extended function (extended using SWIG)
  • Is UDP a reliable protocol for IPC?
  • HTTP Error 404: Not Found when using wget to download a link
  • The Android emulator process has unexpectedly stopped running. The instance is now stopped
  • Vim and snipMate (plugin) - adding new snippet won't work
  • Using electron-usb with electron
  • Application not getting installed on emulator: warning: opening audio input failed
  • Find location of loaded shared library, from in that shared library?
  • Build issues with Visual Studio 11
  • AppDomain Evidence has no Zone?
  • How to build latest Qt from Git repository on windows?
  • How do you determine the optimal disk IO block size on Win32?
  • Perl - Win32 - How to do a non-blocking read of a filehandle from another process?
  • Determining if the Maximize button is available
  • Is ASP.NET MVC a real MVC-Pattern?
  • What is the state of SWT to WPF port?
  • how to log in win32 c++ to the visual studio output window?
  • How do I pass in an owner window to MessageBox.Show on a different thread?
  • How to use the WinInet API from Java?
  • Multiprocessing code works upon import, breaks upon being called
  • How did my Xcode project get changed from iOS project to an OSX project?
  • how to embed manifest file in executable without mt.exe?
  • XNA Number lock affects input
  • Error: Program “make” not found in PATH
  • .NET WinForms Custom Control: how to get a reference to the containing form
  • Mach-O Linker Error When Adding Unit Tests - XCode
  • PHP OCI8 extensions not working with PHP 7 64 bit
  • Share HttpContext code between web and non-web application
  • Using JNA to Get NSWindow from JComponent on mac
  • Why are the debugger memory windows not available in VS 2015?
  • Building jamvm 1.5.4 on OS X Lion
  • Sony Xperia Z Tablet not found by adb
  • Javascript convert timezone issue
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • How do you join a server to an Active Directory (domain)?