问题描述
我正在尝试将带有 mono 3.2.3 的应用程序捆绑到一个独立的可执行文件中.为此,我遵循 this 指南.声明变量后:
mono_version="3.2.3"导出 MONO=/cygdrive/c/progra~2/Mono-$mono_versionmachineconfig=$PROGRAMFILES\Mono-$mono_version\etc\mono\4.5\machine.config导出 PATH=$PATH:$MONO/bin导出 PKG_CONFIG_PATH=$MONO/lib/pkgconfig出口 CC="i686-pc-mingw32-gcc -U _WIN32"
mkbundle --deps 命令无法本地化引用的程序集:
未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集gtk-sharp"或它的依赖项之一.该系统找不到指定的文件.文件名:'gtk-sharp'
执行与单声道 2.10.9 完全相同的操作:
mono_version="2.10.9"导出 MONO=/cygdrive/c/progra~2/Mono-$mono_versionmachineconfig=$PROGRAMFILES\Mono-$mono_version\etc\mono\4.0\machine.config导出 PATH=$PATH:$MONO/bin导出 PKG_CONFIG_PATH=$MONO/lib/pkgconfig出口 CC="i686-pc-mingw32-gcc -U _WIN32"mkbundle --deps --machine-config "$machineconfig" -c UI.exe
给出肯定的结果:
操作系统是:Windows警告:检查您正在捆绑的 machine.config 文件不包含特定于此机器的敏感信息.来源:3 自动依赖:真嵌入:C:userspiotrdesktopauthoringtoolUIindebugUI.exe配置来自:C:userspiotrdesktopauthoringtoolUIindebugUI.exe.config嵌入:C:PROGRA~2MONO-2~1.9libmonogacgtk-sharp2.12.0.0__35e10195dab3c99fgtk-sharp.dll嵌入:C:PROGRA~2MONO-2~1.9libmonogacglib-sharp2.12.0.0__35e10195dab3c99fglib-sharp.dll...嵌入:C:PROGRA~2MONO-2~1.9libmono4.0Mono.Posix.dll机器配置来自:C:Program Files (x86)Mono-2.10.9etcmono4.0machine.config编译:as -o temp.o temp.s
有人知道这种行为的原因吗?我正在使用 64 位版本的 windows 7 和我在官方网站上找到的 Cygwin.代码在 Xamarin Studio 4.2 和 Visual Studio 2010 上编译和测试.
如何在 cygwin + mingw 上使用 mkbundle
使用单声道 4.0.3 测试
在 mono 4.0.3 中,mkbundle 可以正常工作,但要使其正常工作可能会很棘手.
首先,检查您的设置:
- 在不包含空格的路径中安装 Mono/GTK#(即不是 Program Files)
- 设置一个 MinGw/Cygwin 工作编译链(如 那个为在 Windows 上编译单声道).
- 为 mkbundle 定义必需的环境变量:
- mingw 编译器位置应在 Windows PATH 中(由 cmd 使用)
- pkg-config 也应该在 Windows PATH 中
- 使用如下cygwin脚本(可适配为在cmd上运行)
# M_PREFIX 指 Mono 安装# 更多信息,在 Mono 文档中搜索前缀安装M_PREFIX='/cygdrive/c/Mono'导出 DYLD_FALLBACK_LIBRARY_PATH=${M_PREFIX}/lib:${DYLD_FALLBACK_LIBRARY_PATH}导出 LD_LIBRARY_PATH=${M_PREFIX}/lib:${M_PREFIX}/lib/mono/4.5:${LD_LIBRARY_PATH}导出 C_INCLUDE_PATH=${M_PREFIX}/include:${C_INCLUDE_PATH}导出 ACLOCAL_PATH=${M_PREFIX}/share/aclocal:${ACLOCAL_PATH}导出 PKG_CONFIG_PATH=${M_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}# 这里我们添加了 system32 以使 cmd 可用于 mkbundle#/usr/bin 是 mingw 的默认位置导出 PATH=${M_PREFIX}/bin:/cygdrive/c/Windows/system32:/usr/bin:${PATH}出口 CC="i686-pc-mingw32-gcc -U _WIN32"
然后就可以运行了:
mkbundle --deps --keeptemp my.exe my.dll -o bundled.exe
注意事项:- 将mono-2.0.dll
复制到应用程序目录中,因为它应该与捆绑的exe一起分发
cp ${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,如果 mkbundle 在 gcc 调用上失败,这可能会派上用场.- 如果您想手动调用 gcc(可能需要):
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
.
之后你应该得到类似的东西:
<代码>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# 控制台应用程序(在单声道 github)因此可以根据您的需要轻松修改和重新编译它.阅读代码也有助于了解它在底层是如何工作的.
cmd 用法,因为 mkbundle 使用的不同命令是硬编码的,因此它将受益于一些参数化增强.
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 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'
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
gives positive result:
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:userspiotrdesktopauthoringtoolUIindebugUI.exe
config from: C:userspiotrdesktopauthoringtoolUIindebugUI.exe.config
embedding: C:PROGRA~2MONO-2~1.9libmonogacgtk-sharp2.12.0.0__35e10195dab3c99fgtk-sharp.dll
embedding: C:PROGRA~2MONO-2~1.9libmonogacglib-sharp2.12.0.0__35e10195dab3c99fglib-sharp.dll
.
.
.
embedding: C:PROGRA~2MONO-2~1.9libmono4.0Mono.Posix.dll
Machine config from: C:Program Files (x86)Mono-2.10.9etcmono4.0machine.config
Compiling:
as -o temp.o temp.s
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.
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:
- 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 for compiling 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
- Use the following cygwin script (it can be adapted to run on cmd)
# 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"
Then you can run:
mkbundle --deps --keeptemp my.exe my.dll -o bundled.exe
Notes:
- Copy mono-2.0.dll
in the application directory as it should be distributed along the bundled exe
cp ${M_PREFIX}/bin/mono-2.0.dll .
- 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
ForConsoleApplications
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
Anyonecanimprovemkbundle
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"使用单声道 3.2.3 的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!