问题描述
我正在尝试将具有Mono 3.2.3的应用程序捆绑到一个独立的可执行文件中.为此,我正在遵循此指南.声明变量后:
I am trying to bundle the application with mono 3.2.3 to a stand-alone executable. To do so, I am following this guideline. After declarating variables:
mono_version="3.2.3"
export MONO=/cygdrive/c/progra~2/Mono-$mono_version
machineconfig=$PROGRAMFILES\\Mono-$mono_version\\etc\\mono\\4.5\\machine.config
export PATH=$PATH:$MONO/bin
export PKG_CONFIG_PATH=$MONO/lib/pkgconfig
export CC="i686-pc-mingw32-gcc -U _WIN32"
mkbundle --deps命令无法本地化引用的程序集:
mkbundle --deps command cannot localize referenced assemblies:
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'gtk-sharp' or
one of its dependencies. The system cannot find the file specified.
File name: 'gtk-sharp'
与mono 2.10.9执行完全相同的操作:
performing exactly the same operation with mono 2.10.9:
mono_version="2.10.9"
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
export CC="i686-pc-mingw32-gcc -U _WIN32"
mkbundle --deps --machine-config "$machineconfig" -c UI.exe
给出积极的结果:
OS is: Windows
WARNING:
Check that the machine.config file you are bundling
doesn't contain sensitive information specific to this machine.
Sources: 3 Auto-dependencies: True
embedding: C:\users\piotr\desktop\authoringtool\UI\bin\debug\UI.exe
config from: C:\users\piotr\desktop\authoringtool\UI\bin\debug\UI.exe.config
embedding: C:\PROGRA~2\MONO-2~1.9\lib\mono\gac\gtk-sharp\2.12.0.0__35e10195dab3c99f\gtk-sharp.dll
embedding: C:\PROGRA~2\MONO-2~1.9\lib\mono\gac\glib-sharp\2.12.0.0__35e10195dab3c99f\glib-sharp.dll
.
.
.
embedding: C:\PROGRA~2\MONO-2~1.9\lib\mono\4.0\Mono.Posix.dll
Machine config from: C:\Program Files (x86)\Mono-2.10.9\etc\mono\4.0\machine.config
Compiling:
as -o temp.o temp.s
有人知道这种行为的原因吗?我使用的是Windows 7和我在官方网站上找到的Cygwin的64位版本.该代码已在Xamarin Studio 4.2和Visual Studio 2010上进行了编译和测试.
Does anyone know the reason of such behavior? I'm using 64-bit version of windows 7 and the Cygwin I found on the official website. The code was compiled and tested on Xamarin Studio 4.2 and Visual Studio 2010.
推荐答案
如何在cygwin + mingw上使用mkbundle
通过mono 4.0.3测试
在mono 4.0.3中,mkbundle可以工作,但要使其工作起来可能会很棘手.
首先,检查您的设置:
Howto for mkbundle on cygwin + mingw
Tested with mono 4.0.3
In mono 4.0.3, mkbundle works but it can be tricky to make it work.
First, check your setup:
- 在不包含空格的路径中安装Mono/GTK#(即不包含程序文件)
- 设置一个 MinGw/Cygwin 工作编译链(如一个在Windows上编译单声道).
- 为mkbundle定义必需的环境变量:
- mingw编译器的位置应该在Windows PATH中(由cmd使用)
- pkg-config也应该在Windows路径中
- Install Mono/GTK# in a path that doesn't contains spaces (ie not Program Files then)
- Setup a MinGw/Cygwin working compile chain (as the one forcompiling mono on windows).
- Define the mandatory environment variables for mkbundle:
- mingw compiler location should be in the Windows PATH (used by cmd)
- pkg-config should also be in the Windows PATH
# M_PREFIX refers to Mono installation # For more information, search for prefix installation in Mono documentation M_PREFIX='/cygdrive/c/Mono' export DYLD_FALLBACK_LIBRARY_PATH=${M_PREFIX}/lib:${DYLD_FALLBACK_LIBRARY_PATH} export LD_LIBRARY_PATH=${M_PREFIX}/lib:${M_PREFIX}/lib/mono/4.5:${LD_LIBRARY_PATH} export C_INCLUDE_PATH=${M_PREFIX}/include:${C_INCLUDE_PATH} export ACLOCAL_PATH=${M_PREFIX}/share/aclocal:${ACLOCAL_PATH} export PKG_CONFIG_PATH=${M_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH} # Here we added the system32 to make cmd available to mkbundle # /usr/bin is the default location for mingw export PATH=${M_PREFIX}/bin:/cygdrive/c/Windows/system32:/usr/bin:${PATH} export CC="i686-pc-mingw32-gcc -U _WIN32"
然后您可以运行:
mkbundle --deps --keeptemp my.exe my.dll -o bundled.exe
注释: -在应用程序目录中复制
mono-2.0.dll
,因为它应沿着捆绑的exe分发Notes: - Copy
mono-2.0.dll
in the application directory as it should be distributed along the bundled execp ${M_PREFIX}/bin/mono-2.0.dll .
- 如果使用
-z
,则也应复制zlib1.dll. (请注意,gcc调用也会更改).您可能需要更多的dll,具体取决于您对框架功能的使用(并非详尽列表:libglib * .dll,libgmodule * .dll,libgthread * .dll,iconv.dll,intl.dll) -
-c
用于仅生成存根. - 您必须指定捆绑软件所需的所有exe和dll .
-
--keeptemp
将保留temp.c和temp.s,如果在mccundle调用gcc失败时可能会派上用场. - 如果您想手动调用gcc(可能需要):
- if
-z
is used, zlib1.dll should be copied as well. (note that gcc invocation change also). You may need more dll depending on your usage of framework features (not exhaustive list : libglib*.dll, libgmodule*.dll, libgthread*.dll, iconv.dll, intl.dll) -c
is used to generate only stub.- You must specify all exe and dll that are needed for the bundle.
--keeptemp
will keep temp.c and temp.s which could come in handy if mkbundle fail on gcc invocation.- If you want to invoke gcc by hand (and it may be needed):
i686-pc-mingw32-gcc -U _WIN32 -g -o output.exe -Wall temp.c $(pkg-config --cflags --libs mono-2) temp.o
对于控制台应用程序
要使控制台应用程序正常工作,必须从gcc命令中删除 -mwindows .为此,必须调用
pkg-config --cflags --libs mono-2
并删除-mwindows
.For Console Applications
To make console application work you must remove -mwindows from the gcc command. To do that, you must invoke
pkg-config --cflags --libs mono-2
and remove the-mwindows
.之后您应该获得类似的东西:
You should obtain something like that afterwards:
i686-pc-mingw32-gcc -g -o output.exe -Wall temp.c -mms-bitfields -IC:/Mono/include/mono-2.0 -mms-bitfields -LC:/Mono/lib -lmono-2.0 -lws2_32 -lpsapi -lole32 -lwinmm -loleaut32 -l advapi32 -lversion temp.s
任何人都可以改善mkbundle
mkbundle是一个开放源代码的C#控制台应用程序( 在Mono github上 )因此可以根据您的需要轻松对其进行修改和重新编译.阅读代码也可能有助于理解其底层.
cmd 的用法,因为mkbundle使用的不同命令是硬编码的,因此它将受益于一些参数化增强.Anyone can improve mkbundle
mkbundle is an open sourced C# console application (on mono github)so it can be easily modified and recompiled depending on your needs.Reading the code could also be helpful to understand how it works underneath.
cmd usage as the different commands used by mkbundle are hard coded so it would benefit from some parametrization enhancement.这篇关于如何制作"mkbundle -deps"与Mono 3.2.3一起使用的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!