Mono mkbundle causes a strange error

I am trying to compile or link my application using mkbundle. This is the script I execute:

set -o errexit set -o nounset mono_version="3.2.3" export MONO=/cygdrive/c/progra~2/Mono-$mono_version machineconfig=$PROGRAMFILES\\Mono-$mono_version\\etc\\mono\\4.0\\machine.config export PATH=$PATH:$MONO/bin export PKG_CONFIG_PATH=$MONO/lib/pkgconfig icon_name='"icon.ico"' echo "1 ICON $icon_name" > icon.rc export CC="i686-pc-mingw32-gcc icon.o -U _WIN32" output_name=Output.exe mkbundle JiraTempoApp.exe MonoPosixHelper.dll gtk-sharp.dll glib-sharp.dll atk-sharp.dll gdk-sharp.dll glade-sharp.dll glib-sharp.dll pango-sharp.dll RestSharp.dll JiraRestLib.dll --deps --machine-config "$machineconfig" -o $output_name -z rm icon.rc rm icon.o cp $MONO/bin/mono-2.0.dll . cp $MONO/bin/zlib1.dll . ./$output_name 

I had to add MonoPosixHelper.dll because I received an EntryPoint error not found. Now I got this strange error:

 $ ./mkbundle_cygwin.sh OS is: Windows WARNING: Check that the machine.config file you are bundling doesn't contain sensitive information specific to this machine. Sources: 11 Auto-dependencies: True Unhandled Exception: IKVM.Reflection.BadImageFormatException: Exception of type 'IKVM.Reflection.BadImageFormatException' was thrown. at IKVM.Reflection.Reader.PEReader.RvaToFileOffset (UInt32 rva) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Reader.ModuleReader.Read (System.IO.Stream stream) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Reader.ModuleReader..ctor (IKVM.Reflection.Reader.AssemblyReader assembly, IKVM.Reflection.Universe universe, System.IO.Stream stream, System.String location) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Universe.OpenRawModule (System.IO.Stream stream, System.String location) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Universe.OpenRawModule (System.String path) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Universe.LoadFile (System.String path) [0x00000] in <filename unknown>:0 at MakeBundle.LoadAssembly (System.String assembly) [0x00000] in <filename unknown>:0 at MakeBundle.LoadAssemblies (System.Collections.Generic.List`1 sources) [0x00000] in <filename unknown>:0 at MakeBundle.Main (System.String[] args) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: IKVM.Reflection.BadImageFormatException: Exception of type 'IKVM.Reflection.BadImageFormatException' was thrown. at IKVM.Reflection.Reader.PEReader.RvaToFileOffset (UInt32 rva) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Reader.ModuleReader.Read (System.IO.Stream stream) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Reader.ModuleReader..ctor (IKVM.Reflection.Reader.AssemblyReader assembly, IKVM.Reflection.Universe universe, System.IO.Stream stream, System.String location) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Universe.OpenRawModule (System.IO.Stream stream, System.String location) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Universe.OpenRawModule (System.String path) [0x00000] in <filename unknown>:0 at IKVM.Reflection.Universe.LoadFile (System.String path) [0x00000] in <filename unknown>:0 at MakeBundle.LoadAssembly (System.String assembly) [0x00000] in <filename unknown>:0 at MakeBundle.LoadAssemblies (System.Collections.Generic.List`1 sources) [0x00000] in <filename unknown>:0 at MakeBundle.Main (System.String[] args) [0x00000] in <filename unknown>:0 

My.exe works successfully on Windows and Ubuntu, but I'm trying to bundle it so that users do not need to download mono.

+6
source share
2 answers

mkbundle cannot process dynamically linked libraries like MonoPosixHelper.dll . If you want the application to run without mono, you need to deploy this (and other libraries) along with your application on the target system.

If you want to run the application on Ubuntu and do not want the user to install libgtk2.0-cil, you will also need to deploy libatksharpglue-2.so libgdksharpglue-2.so libglibsharpglue-2.so libgtksharpglue-2.so libpangosharpglue-2.so , as required *-sharp.dll .

Then make sure that the target system can find these libraries. Either by defining LD_LIBRARY_PATH , or by creating DLL cards in the build system (which is complicated and can be a bit tedious).

You can also pass the --static parameter to mkbundle to include all the necessary mono libraries directly in your kit (see the man page for more details). Also, run your latest package with MyApp.exe only, not with mono MyApp.exe .

Below are some options for Linux purposes. I did not use mkbundle with mono on Windows, but only compiled with .NET using msbuild , which also creates .msi files.

Option 1:

 $DEPS = "gtk-sharp.dll glib-sharp.dll atk-sharp.dll gdk-sharp.dll glade-sharp.dll glib-sharp.dll pango-sharp.dll RestSharp.dll JiraRestLib.dll" mkbundle --static -o JiraTempoApp JiraTempoApp.exe --deps $DEPS --machine-config "$machineconfig" -z 

Then, make sure you deploy MonoPosixHelper.dll . and other .so files pictured above into your system. To start the application, run

 LD_LIBRARY_PATH=/path/to/deployed/libs:$LD_LIBRARY_PATH JiraTempoApp 

However, I cannot verify if this method works with the LD_LIBRARY_PATH setting.

Option 2:

Build using the same command as in Option 1, but execute from the deployed libraries directory:

 cd /path/to/deployed/libs; /path/to/JiraTempoApp 

Option 3:

This is a little trickier: you need to find your .dll dependency and their .dll.config files in your build system. Copy them to the assembly directory and the dll mapping in the configuration file with a mapping that includes the relative path to the location of the .so files on the target system. Thus, the dll mapping will be packaged using mkbundle, and the packaged executable will be able to find the deployed .so in the target system. I once wrote a Makefile for an application that uses this parameter, maybe this will help you.

+1
source

Are you sure MonoPosixHelper.dll is a managed library? AFAIK mkbundle can only work with managed code. You should still use this DLL (leave it in the folder where it will be loaded, for example, in the folder that you define with LD_LIBRARY_PATH) to avoid the EntryNotFound exception, but you should not use it as an argument to the mkbundle command.

0
source

Source: https://habr.com/ru/post/978406/


All Articles