编译器错误和“ Unkown类型名称”' gtkwidget'使用代码::块
我知道与此类似的问题,不是。虽然我的情况非常相似。打开一个新的GTK项目时,代码:: blocks“ Hello World”程序的前4行是:
#include <stdlib.h>
#include <gdk/gdk.h>
static void helloWorld (GtkWidget *wid, GtkWidget *win)
并且编译器构建日志如下(在类型标记的每个实例中,我只插入了第一个for Brevity)) :
-------------- Build: Debug in graphics project (compiler: GNU GCC Compiler)---------------
gcc -Wall -g -I/usr/include/gtk-4.0/ -I/usr/include/glib-2.0/ -I/usr/lib64/glib-2.0/include/ -I/usr/include/cairo/ -I/usr/include/pango-1.0/ -I/usr/include/harfbuzz/ -I/usr/include/gdk-pixbuf-2.0/ -c "/home/********/Documents/graphics project/main.c" -o obj/Debug/main.o
gcc -o "bin/Debug/graphics project" obj/Debug/main.o
/home/********/Documents/graphics project/main.c:4:25: error: unknown type name ‘GtkWidget’
4 | static void helloWorld (GtkWidget *wid, GtkWidget *win)
| ^~~~~~~~~
什么?!? GTK文档指出,“ GTKWIDGET”是所有事物附近的基础。坦率地说,我不知道这是怎么可能的。通过解释,这里的一千一个-i(如印度)目录是因为由于某种原因,当我通过命令行安装GTK4工具包时,它在/usr/include/include/include/目录,当然,您无法告诉编译器搜索所有子文件夹。我用来安装GTK的特定命令是
sudo yum安装gtk4-devel
,我在fedora 35工作站运行代码:: blocks版本20.03和gcc-c ++ -11.2.1-9.fc.35.x86_64,如果这些事情有所不同。我什至卸载了GTK4并重新安装它,只是为了看看是否可以解决它 - 不。我特别是对编程,尤其是GUI的新手,我基本上只是想努力解决“ Hello World”计划,而没有任何特定的目标。我只想学习。但是,从一分钟开始尝试学习编程以来,这种事情给了我无休止的悲伤,这次我无法搜索答案。哦,第一次为一切。
I know the similar question to this, this ain't it; although my case is extremely similar. The first 4 lines of the Code::Blocks "Hello World" program when you open a new GTK project are this:
#include <stdlib.h>
#include <gdk/gdk.h>
static void helloWorld (GtkWidget *wid, GtkWidget *win)
And the compiler build log goes as follows (with every instance of the type flagged, I only inlcuded the first for brevity):
-------------- Build: Debug in graphics project (compiler: GNU GCC Compiler)---------------
gcc -Wall -g -I/usr/include/gtk-4.0/ -I/usr/include/glib-2.0/ -I/usr/lib64/glib-2.0/include/ -I/usr/include/cairo/ -I/usr/include/pango-1.0/ -I/usr/include/harfbuzz/ -I/usr/include/gdk-pixbuf-2.0/ -c "/home/********/Documents/graphics project/main.c" -o obj/Debug/main.o
gcc -o "bin/Debug/graphics project" obj/Debug/main.o
/home/********/Documents/graphics project/main.c:4:25: error: unknown type name ‘GtkWidget’
4 | static void helloWorld (GtkWidget *wid, GtkWidget *win)
| ^~~~~~~~~
What?!? The GTK documentation states that 'GtkWidget' is the base class for darn near everything. I frankly don't know how this is possible. By way of explanation, the one thousand and one -I (as in India) directories here are because for some reason when I installed the GTK4 toolkit via command line, it put quite a few dependencies inside sub folders in the /usr/include/ directory and of course you can't tell the compiler to search all sub folders. The specific command I used to install GTK was
sudo yum install gtk4-devel
and I'm on Fedora 35 workstation running Code::Blocks version 20.03 and gcc-c++-11.2.1-9.fc.35.x86_64, if any of those things make a difference here. I even uninstalled GTK4 and reinstalled it, just to see if that would fix it--nope. I'm very new to programming in general and GUIs in particular, and I basically just wanted to screw around with the "Hello World" program without any specific goal in mind. I just want to learn. But this sort of thing has given me unending grief since minute one of trying to learn programming, and this time I can't Google the answer. Oh well, first time for everything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在,我在各种GTK3和GTK4项目上主要使用代码块已有一段时间了。我还对IDE进行了一些调整,因为它与构建GTK3或GTK4项目有关,因此为了记住代码块的“ Vanilla” GTK项目的样子,我在虚拟Linux Mint机器上安装了IDE并启动了IDE一个新项目。与您一样,选择“ GTK”作为我的项目类型,IDE在“ main.c”文件中生成了一个样板“ Hello World”程序。但是,我立即注意到我的机器上生成的代码和上面的示例之间的一个差异。 “ inclage”文件集有差异。您的集合具有以下内容:
在我的计算机上,代码的前三行如下:
如果确实,您的代码块版本是引用GDK库(其中包含诸如开罗信息等对象的信息,而不是小部件信息),则可能需要将您的引用修改为“包括”文件&lt; gtk/gtk.h&gt;。要注意的另一件事是,在代码块的“香草”版本中,GTK的版本是代码块20.03的版本,代码块参考GTK2库和构建过程的配置。如果您碰巧打开了该项目的构建信息,则可能会看到一个构建设置,例如“其他编译器选项”下的以下设置:
并且,在链接器选项下,您可能会找到以下内容的库设置,例如:
由于这一事实,如果您的系统上没有GTK2库,则您的代码可能不会编译。 Linux Mint确实具有默认情况下安装的GTK2库。我不知道Fedora是否这样做。
因此,对于您最初的“ Hello World”项目和后续项目,您可能只能修改“ inclage”文件引用到&lt; gtk/gtk.h&gt;看看该程序是否会构建。
我希望解释为您澄清。
问候。
I have been predominantly using Code Blocks for some time now on various GTK3 and GTK4 projects. I have also done some tweaking of the IDE as it pertains to building a GTK3 or GTK4 project, so in order to remember what a "vanilla" GTK project looked like with Code Blocks, I installed the IDE on a virtual Linux Mint machine and launched a new project. As with you, selecting "GTK" as my project type, the IDE generated a boilerplate "Hello World" program in the "main.c" file. However, I noticed one difference right away between the code generated on my machine and your example above. There is a difference in the "include" file set. Your set has the following:
On my machine the first three lines of code are as follows:
If indeed, your version of Code Blocks is referencing the GDK library (which contains information for objects such as cairo information and not the widget information), you may want to revise your reference to "include" file <gtk/gtk.h>. The other thing to note is that in the "vanilla" version of Code Blocks, the version of GTK that version 20.03 of Code Blocks references GTK2 libraries and configurations for the build process. If you happen to open the build information for the project, you are probably going to see a build setting such as the following under "Other Compiler Options":
And, under linker options, you will probably find a library setting such as the following:
Due to that fact, your code probably won't compile if do not have the GTK2 libraries on your system. Linux Mint does have the GTK2 libraries installed by default. I do not know if Fedora does that.
So for your initial "Hello World" project and subsequent projects, you could probably just revise the "include" file reference to <gtk/gtk.h> and see if the program will build.
I hope that explanation clarifies things for you.
Regards.