无法使用GTK编译代码 [英] Unable to compile code with GTK
问题描述
我想学会使用GTK3,但我无法编译第一个例子。
我安装了 MSYS2
并运行:
pacman -S mingw-w64-x86_64-gtk3
其次是:
pre $ p $ c $ p $ s $ m $ $ $
$ $ $ $ $ pre>
和:
pacman -S mingw-w64-x86_64 -devhelp
我将它安装在 c:\MSYS64
这是默认位置,但当我尝试并运行时
gcc`pkg-config --cflags gtk + -3.0` -o example-0 example-0.c`pkg-config --libs gtk + -3.0`
编译简单窗口教程
#include< gtk / gtk.h>
static void
activate(GtkApplication * app,
gpointer user_data)
{
GtkWidget * window;
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window),Window);
gtk_window_set_default_size(GTK_WINDOW(window),200,200);
gtk_widget_show_all(window);
int main(int argc,char ** argv)
{
GtkApplication * app;
int状态;
app = gtk_application_new(org.gtk.example,G_APPLICATION_FLAGS_NONE);
g_signal_connect(app,activate,G_CALLBACK(activate),NULL);
status = g_application_run(G_APPLICATION(app),argc,argv);
g_object_unref(app);
返回状态;
}
出现错误:
C:\Users\Simon\Desktop\webbrowser> gcc`pkg-config --cflags gtk + -3.0` -o example-1 example-1.c `pkg-config --libs gtk + -3.0`
gcc:错误:`pkg-config:没有这样的文件或目录
gcc:错误:gtk + -3.0`:没有这样的文件或目录
gcc:error:example-1.c:没有这样的文件或目录
gcc:错误:`pkg-config:没有这样的文件或目录
gcc:error:gtk + -3.0`:没有这样的文件或目录
gcc:错误:无法识别的命令行选项'--cflags'
gcc:错误:无法识别的命令行选项'--libs'
gcc:致命错误:无输入文件
编译终止。
这是来自命令提示符,所以我想尝试使用MSYS2 shell,但是我得到一个错误, code> -bash:gcc:找不到命令。我也尝试将脚本移动到 C:\msys64\home\
但返回相同的错误。
某处我跳过某些东西或者做错了什么,但我真的不明白是什么。我一直在尝试过去的一个月(开启和关闭),并会非常感谢任何帮助。
如果有帮助,我在Windows上使用MinGW。
gcc:error:`pkg-config:No such file or directory
您缺少 pkg-config
。请阅读所有 Windows上的GTK + 说明。我写了那个页面,但无法猜测你将要使用的很多语言。如果您选择C或C ++,则需要第5步,因为您需要基本构建工具,如 pkg-config
。我特意给了一个命令,选择了许多工具,以避免一个接一个地挑选它们,有人错过了一个工具。
所以请运行:
pacman -S mingw-w64-x86_64-toolchain base-devel
反馈欢迎提供如何改进说明页面。
I want to learn to use GTK3 but I am not able to compile the first example.
I installed MSYS2
and ran:
pacman -S mingw-w64-x86_64-gtk3
followed by:
pacman -S mingw-w64-x86_64-glade
and:
pacman -S mingw-w64-x86_64-devhelp
I installed it at c:\MSYS64
which is the default location but when I try and run
gcc `pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0`
to compile the Simple Window tutorial
#include <gtk/gtk.h>
static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_widget_show_all (window);
}
int main (int argc, char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
I get an error:
C:\Users\Simon\Desktop\webbrowser>gcc `pkg-config --cflags gtk+-3.0` -o example-1 example-1.c `pkg-config --libs gtk+-3.0`
gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: example-1.c: No such file or directory
gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: unrecognized command line option '--cflags'
gcc: error: unrecognized command line option '--libs'
gcc: fatal error: no input files
compilation terminated.
This is from command prompt so I thought of trying to use MSYS2 shell but I got an error saying -bash: gcc: command not found
. I also tried moving the script to C:\msys64\home\
but that returns the same error.
Somewhere I have skipped something or am doing something wrong but I really cannot understand what. I have been trying for the past month (on and off) and would really appreciate any help.
I use MinGW on Windows if that helps.
gcc: error: `pkg-config: No such file or directory
You're missing pkg-config
. Please read all the GTK+ on Windows instructions. I wrote that page but can't guess wich language you're going to use. Step 5 there is needed if you chose C or C++, as you need basic build tools like pkg-config
. I deliberately gave a command that pick lots of tools to avoid picking them one by one and someone missing a tool.
so please run:
pacman -S mingw-w64-x86_64-toolchain base-devel
Feedback welcome on how to improve the instructions page.
这篇关于无法使用GTK编译代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!