在Windows上使用Mkbundle创建C

在Windows上使用Mkbundle创建C

本文介绍了在Windows上使用Mkbundle创建C#可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从控制台应用程序创建可执行文件.我已经安装了mono,cygwin(mingw-gcc,mingw-zlib1,mingw-zlib-devel,pkg-config),并在.bashrc文件中添加了以下几行

Im trying to create an executable from a console application.I have installed mono,cygwin (mingw-gcc, mingw-zlib1, mingw-zlib-devel, pkg-config) and I have added the following lines to my .bashrc file

export PKG_CONFIG_PATH=/cygdrive/c/progra~1/Mono-3.2.3/lib/pkgconfig
export PATH=$PATH:/cygdrive/c/progra~1/Mono-3.2.3/bin
export CC="i686-pc-mingw32-gcc -U _WIN32"

但是,每次我尝试使用mkbundle时,都会收到以下消息

But everytime I try to use mkbundle I receive the following message

是否有一种方法可以使mkbundle在Windows上正常工作??

Is there a way to make mkbundle work properly on windows.?

(我使用的是Windows 7 x86,mono 3.2.3,我在官方网站上发现的cygwin,xamarin Studio 4.2和网络框架4)

(Im using windows 7 x86, mono 3.2.3, the cygwin I found on the official website, xamarin studio 4.2 and net framwork 4)

推荐答案

在Windows下,当前的Mono版本中仍然存在此问题.发生这种情况是因为单声道团队将默认GC切换为SGEN.因此,当您尝试使用mkbundle时,如在错误mkbundle实用程序中看到的那样,请尝试找到 mono-2 库,但此库未包含在安装程序中,因此您将失败.为了解决这个问题,您应该将mkbundle配置为使用 libmonosgen-2.0 而不是 mono-2 .让我们尝试这样做.

This problem is still presented in the current mono version under the Windows. This happened because of mono team switched default GC to SGEN. So when you try to use mkbundle as you can see in your error mkbundle utility try to find mono-2 library but this lib didn't included in setup and you have a fail. To solve this you should configure mkbundle to use libmonosgen-2.0 instead of mono-2. Let's try to do this.

关键时刻正在设置此变量:

The key moment is setting this variable:

export PKG_CONFIG_PATH=/cygdrive/c/progra~1/Mono-3.2.3/lib/pkgconfig

如果转到此目录,将看到很多 *.pc 文件(程序包配置).该文件负责捆绑过程中链接库的配置.由于某些原因,mono团队将软件包配置文件和库硬编码为 mono-2 (请参见第492行).我们如何在不重建 mkbundle 的情况下进行修复?解决方案是使用下一个捆绑脚本:

If you go to this directory you will see a lot of *.pc files (package config). This files are responsible for configuration of linking libraries during bundling process. For some reasons mono team hard coded package config file and library to mono-2 (see this line 492). How could we fix it without rebuilding mkbundle? The solution is to use the next bundle script:

# Mono paths
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
# Compiller
export CC="i686-pc-mingw32-gcc -U _WIN32"
# Output file name
output_name=Prog.exe
# Produce stub only, do not compile
mkbundle --deps --machine-config "$machineconfig" -c Program.exe
# Produce helper object file. You may see errors at this step but it's a side effect of this method.
mkbundle --deps --machine-config "$machineconfig" -oo temp.o Program.exe
# Compile. Pay attention where I use monosgen-2
i686-pc-mingw32-gcc -U _WIN32 -g -o "$output_name" -Wall temp.c `pkg-config --cflags --libs monosgen-2` temp.o
# Copy libmonosgen-2.dll
cp $MONO/bin/libmonosgen-2.0.dll .
# Run
./$output_name

这篇关于在Windows上使用Mkbundle创建C#可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:08