【问题标题】:C# program doesn't work under mono in Linux.C# 程序在 Linux 的单声道下无法运行。
【发布时间】:2012-01-30 22:40:58
【问题描述】:

我正在尝试让我用 Visual C# 2010 编写的程序在 Linux 上运行。为此,我使用了 mkbundle 功能,因此潜在客户不必安装单声道。不幸的是,我对 Linux 或 Mono 不了解,所以我只是跟着这个:c# cywgwin mono mkbundle windows 7 - cannot compile file

但由于某种原因,mkbundle 在最后写入 [FAIL],表示“没有这样的文件或目录”。我在下面粘贴了全文。有人知道怎么解决吗?

$ mkbundle -o MyProgram MyProgram.exe --deps
OS is: Windows
Sources: 1 Auto-dependencies: True
   embedding: C:\cygwin\home\Synaps\MyProgram.exe
   embedding: C:\Mono-2.10.8\lib\mono\4.0\mscorlib.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.Drawing.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\Mono.Security.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.Configuration.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.Xml.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.Security.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.Windows.Forms.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\Accessibility.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\Mono.WebBrowser.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\Mono.Posix.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.Data.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\Mono.Data.Tds.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.Transactions.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\System.EnterpriseServices.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\AForge.Imaging.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\AForge.dll
   embedding: C:\Mono-2.10.8\lib\mono\4.0\AForge.Math.dll
Compiling:
as -o temp.o temp.s
gcc -mno-cygwin -g -o MyProgram -Wall temp.c `pkg-config --cflags --libs mono-2|d
os2unix`  temp.o
: No such file or directory
temp.c: In function `main':
temp.c:143: warning: implicit declaration of function `g_utf16_to_utf8'
temp.c:143: warning: assignment makes pointer from integer without a cast
temp.c:158: warning: assignment makes pointer from integer without a cast
[Fail]

当我尝试在 Linux 虚拟机上使用 mkbundle 时,我成功获得了 Linux 可执行文件,但每当我在 Ubuntu Linux VM(通过 Oracle VM Virtual Box)下运行该程序时都会出现以下错误:

Unhandled Exception: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap.SetResolution (Single xDpi, Single yDpi) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:SetResolution (single,single)
  at AForge.Imaging.ColorReduction.ColorImageQuantizer.ReduceColors (System.Drawing.Bitmap image, Int32 paletteSize) [0x00000] in <filename unknown>:0 
  at FootMeasure.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap.SetResolution (Single xDpi, Single yDpi) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:SetResolution (single,single)
  at AForge.Imaging.ColorReduction.ColorImageQuantizer.ReduceColors (System.Drawing.Bitmap image, Int32 paletteSize) [0x00000] in <filename unknown>:0 
  at FootMeasure.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 

【问题讨论】:

  • 请发布pkg-config --cflags --libs mono-2|dos2unix的输出
  • $ pkg-config --cflags --libs mono-2|dos2unix -mno-cygwin -mms-bitfields -mwindows -IC:/Mono-2.10.8/include/mono-2.0 -mno -cyg win -mms-bitfields -mwindows -LC:/Mono-2.10.8/lib -lmono-2.0 -lws2_32 -lpsapi -l ole32 -lwinmm -loleaut32 -ladvapi32 -lversion
  • 如果你禁用 gcc 警告?
  • 您问的是 Linux,但您的操作系统是 Windows?为什么不在真正的Linux 系统上尝试mono?在 Windows 上运行 mkbundle 不会产生 linux 可执行文件
  • 没错,问题不再是mkbundle,而是为什么程序不能在mono下运行。我已经修改了问题的名称。

标签: .net linux visual-studio-2010 mono mkbundle


【解决方案1】:

正如我在评论中所说,如果你想生成一个自给自足的 Linux 可执行二进制文件,你不应该在 Windows 上使用mkbundle您应该在 Linux 上运行 mkbundle 以获得 Linux 可执行文件(您可能应该关心 32 位的 Linux-X86 和 64 位的 Linux-x86-64,它们是不同的)。 p>

我建议您在 Linux 机器中编译和运行您的应用程序(如果需要,您甚至可以在 VM 中安装 Linux 系统)。因此,最简单的方法是在您的计算机上安装 Linux 发行版(例如 Debian)。

我认为您不会轻易找到能够在 Windows 机器上编译针对 Linux 的 Mono 程序的交叉编译器

而您正在做的事情(在 Windows 上运行 mkbundle)正在生成一个 Windows 可执行文件(用于 Cygwin),它无法为您提供 Linux 二进制可执行文件,无论您尝试什么选项。

【讨论】:

  • 我已经完成了,请查看已编辑的问题以获取详细信息。尽管 mkbundle 成功运行,但我又遇到了一些错误。
  • @TofigHasanov 程序是否可以在不运行 mkbundle 的情况下在 linux VM 上运行?
  • 当我简单地使用“mono ProgramName.exe 参数”时,它会产生与运行“mkbundled”版本时相同的错误(以 Unhandled Exception: System.ArgumentException: 开头的那个)跨度>
  • 所以你必须调试那个问题。
  • 似乎问题出在某些 AForge 库中。我不得不自己重写一些过滤器,然后效果很好。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-26
  • 2019-07-31
相关资源
最近更新 更多