简体   繁体   English

只需双击即可运行使用MSYS2构建的GTK +应用程序

[英]Running a GTK+ application built with MSYS2 by just double clicking it

I have a simple window application, built with MSYS2 , which I want to be able to run outside of the MSYS2 MinGW shell, just by double-clicking on the application. 我有一个简单的窗口应用程序,使用MSYS2构建 ,我希望能够在MSYS2 MinGW shell之外运行,只需双击应用程序即可。

The problem is that when I want to run the application it must be though the MSYS MinGW prompt otherwise it returns an error. 问题是,当我想运行应用程序时,它必须通过MSYS MinGW提示,否则它会返回错误。

The code execution cannot proceed because libgio-2.0-0.dll was not found. Reinstalling the program may fix this problem

I tried including (by copying the files to the location of my exe) libgio-2.0-0.dll and more errors appeared saying libraries were missing. 我尝试包括(通过将文件复制到我的exe的位置) libgio-2.0-0.dll并且出现了更多错误,说库已丢失。 I included those files too. 我也包括这些文件。 I have shown the files I included below: 我已经显示了下面包含的文件:

libffi-6.dll
libgdk-3-0.dll
libglib-2.0-0.dll
libgmodule-2.0-0.dll
libgtk-3-0.dll
libgobject-2.0-0.dll
libgio-2.0-0.dll
libatk-1.0-0.dll
libcairo-gobject-2.dll
libcairo-2.dll
libepoxy-0.dll
libpcre-1.dll
libwinpthread-1.dll
libgdk_pixbuf-2.0-0.dll
libpango-1.0-0.dll

In the end an error appears saying: 最后出现一个错误:

The application was unable to start correctly (0xc000007b).  Click OK to close the application.

I found what the error message means: 我发现了错误消息的含义:

That particular error code refers to an invalid image format. 该特定错误代码指的是无效的图像格式。 However, what the error code usually means is that you are trying to run a program that is intended to work with a 64 bit Windows operating system, but that you only have a 32 bit OS. 但是,错误代码通常意味着您尝试运行的程序旨在使用64位Windows操作系统,但您只有32位操作系统。

However it does not help as I am running an x64 computer. 但是,因为我正在运行x64计算机,所以没有用。 The DLL are x64 as well as the exe. DLL是x64以及exe。

www.gtk.org says GTK+ depends on some libraries and apart from what I have done above I cannot think of any solution and cannot find any documentation on what dependencies to include in order to not run it through the MSYS prompt. www.gtk.org说GTK +依赖于某些库,除了我上面所做的,我想不出任何解决方案,也无法找到任何关于要包含哪些依赖项的文档,以便不通过MSYS提示运行它。

So what do I need to do to get my window working? 那么我需要做些什么来让我的窗户工作? The application is fine there is a problem with the dependencies. 应用程序很好,依赖项存在问题。

Secondly what are the dependencies I need to include (or have I listed all of them in which case what is going wrong with my window) for the script I gave? 其次,对于我给出的脚本,我需要包含哪些依赖项(或者我列出了所有这些依赖项,在这种情况下我的窗口出了什么问题)?

And finally is there an easier way than what I am trying to do to get all the necessary dependencies? 最后是否有一种比我想要做的更简单的方法来获得所有必要的依赖?

The system needs to be able to find the shared libraries. 系统需要能够找到共享库。 On a Linux system, this is through the linker, usually ld . 在Linux系统上,这是通过链接器,通常是ld The configuration for where to find them lies in /etc/ld.so.conf and /etc/ld.so.conf.d . 找到它们的配置位于/etc/ld.so.conf/etc/ld.so.conf.d

Now on Windows, this doesn't exist. 现在在Windows上,这不存在。 That's why the environment variable PATH commonly is used for that, and sometimes modified by installers. 这就是环境变量PATH通常用于此的原因,有时也会被安装程序修改。 But changing the PATH for every program is annoying and forbids relocation (moving the whole app directory and running the app from elsewhere). 但是改变每个程序的PATH是令人讨厌的,并且禁止重新定位(移动整个app目录并从其他地方运行应用程序)。 So you may just create an empty directory, create a bin directory in it, and copy your application binary and the GTK+ libraries there. 所以你可以创建一个空目录,在其中创建一个bin目录,然后在那里复制你的应用程序二进制文件和GTK +库。 That should work because the current directory is searched before the PATH variable on Windows. 这应该工作,因为在Windows上PATH变量之前搜索当前目录

So what you have done is correct. 所以你所做的是正确的。 The problems you have are similar to app redistribution, ie. 您遇到的问题类似于应用重新分配,即。 gathering the necessary bits to distribute a software on another computer. 收集必要的位以在另一台计算机上分发软件。 This isn't the most documented part on the GTK+ website unfortunately. 不幸的是,这不是GTK +网站上记录最多的部分。 Have you tried with a an application that doesn't use the GtkApplication class? 您是否尝试过不使用GtkApplication类的应用程序?

I fixed it by including library through command line like this. 我通过这样的命令行包含库来修复它。

gcc pkg-config --cflags gtk+-3.0 -o example-1 example-1.c pkg-config --libs gtk+-3.0 gcc pkg-config --cflags gtk+-3.0 -o example-1 example-1.c pkg-config --libs gtk+-3.0

and run it using mingw64.exe that comes with MSYS2 installer 并使用自带的mingw64.exe运行MSYS2安装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM