题
我写了一些类似控制台“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 中。
解决方案
首先,准备开发环境:
- 安装单声道。例如,您已将其安装到
C:\Soft\Mono
". - 安装Cygwin。选择要安装的软件包时,选择以下:GCC-MINGW,MINGW-ZLIB,PKG-CONFIG,NANO。
- 启动Cygwin Bash Shell(使用链接或“
bash --login -i
“ 命令)。 - 打开 ”
$HOME/.bashrc
用“ nano”(“nano ~/.bashrc
”)。不要使用不保留线路末端的编辑器(“ cr”,“ lf”,“ cr/lf”或其他),或者会损坏文件! 在文件末尾添加以下行:
export PKG_CONFIG_PATH=/cygdrive/c/Soft/Mono/lib/pkgconfig export PATH=$PATH:/cygdrive/c/Soft/Mono/bin
重新启动Cygwin bash壳。
之后,您可以用“ mkbundle”编译组件:
- 执行以下命令:”
mkbundle -c -o host.c -oo bundle.o --deps YourAssembly.exe <additional arguments>
“。您也可以选择通过”-z
“压缩结果捆绑包。您应该获得“ host.c”和“ bundle.o”文件。 在“ host.c”中,您应该删除“ _WIN32”“分支”(除外
#include <windows.h>
“一个)。它行不通。您可以通过添加来做到这一点”#undef _WIN32
“紧随其后之后:#ifdef _WIN32 #include <windows.h> #endif
所以你会得到:
#ifdef _WIN32 #include <windows.h> #endif #undef _WIN32
执行以下命令:”
gcc -mno-cygwin -o ResultantBundle.exe -Wall host.c
`pkg-config --cflags --libs mono-2|dos2unix`
bundle.o <additional arguments>
“。如果您在步骤2中添加了一个-Z附加参数,则必须在此步骤中添加-Lz附加参数。- 您将获得“ RustantBundle.exe”。这是您的单声道应用程序包装为独立的可执行文件。
- 它仍然需要“ mono-2.0.dll”,并且您在开发过程中依赖一些额外的DLL-S和资源(例如,它可能需要GTK#本机DLL-S),但是它不需要运行完整的单声道运行时。
其他提示
只想添加,如果您将-Z传递到mkbundle,则需要将-lz传递给GCC。我遇到了一些问题,可以将Winforms和Net访问正常工作的应用程序获得,并且我必须从C: mono etc etcon mono 4.0 Machine.config复制Machine.config到我的应用程序所在。然后,我将-schine-config Machine.config传递给mkbundle。
所有这些步骤都非常令人困惑和令人沮丧,为什么不像键入mkbundle -deps app.exe那样简单?我尝试更改Mkbundle使用的模板并自己编译,但不会运行。我现在走到了下载单声道来源并尝试构建整个内容,但我怀疑它会起作用。如果有人可以解释Mkbundle的到底是什么使它变得如此烦人,我将对贡献感兴趣。
获得 temp.o 和 temp.c 后,您可以将它们添加到 Visual C++ 中,以使用其他源创建 Windows 应用程序。