7

我写了一些控制台“Hello world”之类的应用程序。并遵循c# cywgwin mono mkbundle windows 7 - 无法编译文件答案。但我有:

$ mkbundle -o Fur Furries.exe --deps -z
OS is: Windows
Sources: 1 Auto-dependencies: True
  embedding: C:\Monotest\Furries.exe
  compression ratio: 40.43%
  embedding: C:\Soft\Mono\lib\mono\4.0\mscorlib.dll
  compression ratio: 34.68%
Compiling:
as -o temp.o temp.s
gcc -mno-cygwin -g -o Fur -Wall temp.c `pkg-config --cflags --libs mono-2|dos2un
ix` -lz temp.o
temp.c: In function `main':
temp.c:173: warning: implicit declaration of function `g_utf16_to_utf8'
temp.c:173: warning: assignment makes pointer from integer without a cast
temp.c:188: warning: assignment makes pointer from integer without a cast
/tmp/ccQwnxrF.o: In function `main':
/cygdrive/c/Monotest/temp.c:173: undefined reference to `_g_utf16_to_utf8'
/cygdrive/c/Monotest/temp.c:188: undefined reference to `_g_utf16_to_utf8'
collect2: ld returned 1 exit status
[Fail]

它在 Windows XP 中。

4

3 回答 3

13

首先准备开发环境:

  1. 安装单声道。例如,您已将其安装到“ C:\Soft\Mono”中。
  2. 安装 Cygwin。选择要安装的软件包时,请选择以下内容:gcc-mingw、mingw-zlib、pkg-config、nano。
  3. 启动 Cygwin Bash shell(使用链接或“ bash --login -i”命令)。
  4. $HOME/.bashrc用“nano”(“ ”)打开“ ” nano ~/.bashrc。不要使用不保留行尾的编辑器(“CR”、“LF”、“CR/LF”或其他),否则会损坏文件!
  5. 将以下行添加到文件末尾:

    export PKG_CONFIG_PATH=/cygdrive/c/Soft/Mono/lib/pkgconfig
    export PATH=$PATH:/cygdrive/c/Soft/Mono/bin
    
  6. 重新启动 Cygwin Bash shell。

之后,您可以使用“mkbundle”编译您的程序集:

  1. 执行以下命令:“ mkbundle -c -o host.c -oo bundle.o --deps YourAssembly.exe <additional arguments>”。您也可以选择传递“ -z”来压缩结果包。你应该得到“host.c”和“bundle.o”文件。
  2. 在“host.c”中,您应该删除“_WIN32”“分支”(“ #include <windows.h>”之一除外)。它不起作用。你可以通过#undef _WIN32在下面的行之后添加“”来做到这一点:

    #ifdef _WIN32
    #include <windows.h>
    #endif
    

    所以你会得到:

    #ifdef _WIN32
    #include <windows.h>
    #endif
    #undef _WIN32
    
  3. 执行以下命令:“ gcc -mno-cygwin -o ResultantBundle.exe -Wall host.c `pkg-config --cflags --libs mono-2|dos2unix` bundle.o <additional arguments>”。如果您在步骤 2 中添加了 -z 附加参数,则必须在此步骤中添加 -lz 附加参数。

  4. 您将获得“ResultantBundle.exe”。这是打包为独立可执行文件的 Mono 应用程序。
  5. 它仍然需要“mono-2.0.dll”和一些您在开发过程中依赖的额外 DLL-s 和资源(例如,它可能需要 GTK# 本机 DLL-s),但它不需要完整的 Mono 运行时来运行。
于 2010-12-18T11:16:15.853 回答
1

只是想补充一点,如果您将 -z 传递给 mkbundle,那么您需要将 -lz 传递给 gcc。我在让具有 winforms 和网络访问权限的应用程序正常工作时遇到了一些问题,我不得不将 machine.config 从 C:\Mono\etc\mono\4.0\machine.config 复制到我的应用程序所在的位置。然后我将 --machine-config machine.config 传递给 mkbundle。

所有这些步骤都非常令人困惑和令人沮丧,为什么不像键入 mkbundle --deps app.exe 那样简单?我尝试更改 mkbundle 使用的模板并自己编译它,但它不会运行。我现在已经下载了单声道源并尝试构建整个东西,但我怀疑它会起作用。如果有人能解释一下 mkbundle 到底发生了什么让这变得如此烦人,我将有兴趣做出贡献。

于 2011-09-06T15:18:41.387 回答
0

获得 temp.o 和 temp.c 后,您可以将它们添加到 Visual c++ 中,以使用其他来源制作 Windows 应用程序。

于 2015-01-23T03:51:41.630 回答