c - GTK : Visual Studio Issue

标签 c visual-studio visual-c++ gtk

出于开发原因,我必须构建 GTK 堆栈的调试版本。 构建它之后,我为 GTK 设置了 pkg-config,下面是我的 Visual Studio 中的示例程序

#include<gtk/gtk.h>
#include<stdio.h>
#include<string.h>

int main(int argv, char* argc)
{
    GtkWidget *window, *label;
    gtk_init(&argv, &argc);
    window = gtk_window_new(GTK_WINDOW_TOP_LEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Window");
    gtk_window_set_size_request(window, 300, 100);
    label = gtk_label_new("Click Me");
    gtk_label_set_selectable(GTK_LABEL(label), TRUE);
    gtk_container_add(GTK_CONTAINER(window), label);
    g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(key_press_event), label);
    gtk_window_show_all(window);
    gtk_main();
}

static gboolean key_press_event(GtkWidget* window, GdkEvent* event, gpointer label)
{
    GtkWidget* newlabel;
    newlabel = GTK_LABEL(label);
    const gchar wtitle[100];
    strncpy(wtitle, gtk_window_get_title(GTK_WINDOW(window)), sizeof(wtitle));
    gtk_window_set_title(GTK_WINDOW(window),gtk_label_get_text(GTK_LABEL(newlabel)));
    gtk_label_set_text(GTK_LABEL(newlabel), wtitle);
    return false;
}

下面是我的 pkg-config --cflags gtk-3-vs12 --msvc-syntax,我已将其包含在项目属性 -> C/C++ -> 命令行 -> 其他选项中:

/Ic:/gtk_compilation/vs12/win32/include /Ic:/gtk_compilation/vs12/win32/include/gtk /Ic:/gtk_compilation/vs12/win32/include/gdk /Ic:/gtk_compilation/vs12/win32/include/pango /Ic:/gtk_compilation/vs12/win32/include/atk /Ic:/gtk_compilation/vs12/win32/include/cairo  /Ic:/gtk_compilation/vs12/win32/include/fontconfig /Ic:/gtk_compilation/vs12/win32/include/gdk-pixbuf /Ic:/gtk_compilation/vs12/win32/include/glib 

下面是我的 pkg-config --libs gtk-3-vs12 --msvc-syntax,我已将其包含在项目属性 -> 链接器 -> 命令行 -> 其他选项中:

/libpath:c:/gtk_compilation/vs12/win32/lib gtk-3-vs12.lib gdk3-win32.lib gdi32.lib imm32.lib shell32.lib ole32.lib -Wl,-luuid pangocairo.lib pangowin32.lib pango-1-vs12.lib m.lib atk-1-vs12.lib cairo-gobject.lib cairo-vs10.lib gdk_pixbuf-2-vs12.lib gio-2-vs12.lib gobject-2-vs12.lib glib-2-vs12.lib intl.lib 

我仍然收到以下错误:

Error   9   error C2065: 'false' : undeclared identifier    c:\users\sajith\documents\visual studio 2013\projects\consoleapplication8\consoleapplication8\testapp.c 28  1   ConsoleApplication8
Error   3   error C2065: 'GTK_WINDOW_TOP_LEVEL' : undeclared identifier c:\users\sajith\documents\visual studio 2013\projects\consoleapplication8\consoleapplication8\testapp.c 9   1   ConsoleApplication8
Error   5   error C2065: 'key_press_event' : undeclared identifier  c:\users\sajith\documents\visual studio 2013\projects\consoleapplication8\consoleapplication8\testapp.c 15  1   ConsoleApplication8

谁能启发我解决这个问题?

最佳答案

首先,常量名称不是GTK_WINDOW_TOP_LEVEL,而是GTK_WINDOW_TOPLEVEL

其次,您需要先声明key_press_event(),然后才能在main() 中引用它。您有两个选择:将函数本身移动到 main() 之前,或者添加行

static gboolean key_press_event(GtkWidget* window, GdkEvent* event, gpointer label);

main() 之前。

第三,您希望 key_press_event() 返回 FALSE,而不是 false

关于c - GTK : Visual Studio Issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33255976/

相关文章:

visual-studio - Visual Studio 项目为空?

c# - 如何为 Visual Studio 项目添加和编译自定义 'Platform' 开关?

visual-c++ - CWnd 到 CComboBox 的 dynamic_cast 在 OnSize 函数中产生一个空指针

c - 这段代码是否是整数溢出

检查相等指针和内存汇总

asp.net-mvc - 如何让 MvcBuildViews 在出错时继续其他 View ?

c++ - 我的窗口句柄未使用,无法评估

c - 为什么转换 'out of range integer to integer' 会导致 IB,但转换 'out of range floating-point to integer' 会导致 UB?

c - 在 c 中使用 p 线程编写并行快速排序

c++ - 如何使用 scons 2.3 visual express 2012 构建 C++ 项目?