如果可能的话,我将开始开发一个应该在Linux和Windows上运行的软件项目。由于我已经有了一些使用C#的经验,所以我渴望在这个项目中使用它。我认为使用.NET Core 3和GTK# 3.22应该不会有问题,因为.NET核心应用程序应该是跨平台的。据我所知,GTK#应该在任何地方都能工作,GTK+在同一版本中也是可用的。
为什么是c#?嗯,我只是喜欢这种语言,我想要使用的是c#的ECS框架。
到目前为止,我已经在Visual中设置了一个针对.NET核心3的测试控制台应用程序项目,并添加了一个GTK#专用NuGet软件包。
我编写了一个简单的Hello程序来测试环境。
using System;
using Gtk;
namespace GTKTest
{
class Program
{
static void Main(string[] args)
{
Application.Init();
Window win = new Window("Hello GTK");
Label lbl = new Label("This is a test GTK App written with C# for GNU/Linux and Windows");
win.DeleteEvent += Win_DeleteEvent;
win.Add(lbl);
win.ShowAll();
Application.Run();
win.Dispose();
Console.Write("Press any key...");
Console.ReadKey();
}
private static void Win_DeleteEvent(object o, DeleteEventArgs args)
{
Application.Quit();
args.RetVal = true;
}
}
}
当我从2019年运行这段代码时,
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'Gtk.Application' threw an exception.
Source=GtkSharp
StackTrace:
at Gtk.Application.Init()
at GTKTest.Program.Main(String[] args) in D:\Workspace\VSRepos\C#\GTKTest\Program.cs:line 10
Inner Exception 1:
DllNotFoundException: Gtk
在搜索解决方案时,我安装了mono和来自此页面的GTK# for Windows。如果我坚持使用.NET核心,那么这个单一的部分就不应该是必要的。
我遗漏了什么?我做错了什么?我想要达到的目标,就像我想象的那样吗?我也感兴趣的一些替代方案,如何编程跨平台的GUI-软件与C#。我无意中发现了electron.js,但我听说它内存开销很大,我对javascript并不感兴趣。AvaloniaUI听起来很有趣,但我认为上述方法会更好。
编辑:在添加msys路径(如建议的在步骤3中 )之后,我会在上面的异常之前得到以下错误。错误声明在dll中找不到过程入口点。
发布于 2022-04-19 23:22:19
我知道这是个老问题,但谷歌很喜欢。我也遇到过类似的问题。有很多指南是很容易谷歌,但很难让他们工作。以下是2022年4月帮助我的指南:
步骤1:安装MSYS2,下载MSYS2安装程序并遵循安装说明。
步骤2:安装GTK+3打开MSYS2外壳,然后运行:pacman -S mingw-w64-x86_64-gtk3
步骤3:修改路径变量,以便可以找到库
Open up Control Panel
Go to System and Security > System
Click on the Advanced system settings link
Click on Environment Variables... button
Under System variables find the Path variable and select it
Click the Edit button
Add either ;C:\msys64\mingw64\bin or ;C:\msys32\mingw32\bin to the end of the variable, depending on your system architecture
Click OK, and you are done
Restart your system for the changes to apply
要运行GtkSharp示例项目,您还需要:pacman -S mingw-w64-x86_64-gtksourceview4
,否则它会引发...System.DllNotFoundException: GtkSource: libgtksourceview-4-0.dll...
然后,您可以从GtkSharp或nuget安装这里。
https://stackoverflow.com/questions/58117404
复制相似问题