gpt4 book ai didi

c - 如何在 Visual Studio 代码中添加 gtk 库?

转载 作者:行者123 更新时间:2023-12-03 09:50:00 30 4
gpt4 key购买 nike

我尝试在我的 Arch Linux 上的 Visual Studio 代码中将 gtk 库添加到我的文件中,但它强调“#include 行并写道:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/home/mikhailkhr/My projects/C projects/Test/Test.c).cannot open source file "glibconfig.h" (dependency of "gtk/gtk.h")

It does compile this file with:

 gcc `pkg-config gtk+-3.0 --cflags` ProgName.c `pkg-config gtk+-3.0 --libs`

But why does it underline this?
And how to fix this?

Thanks.

Sorse code:

#define _PROGRAM_NAME "whoami"
#include <stdlib.h>
#include <pwd.h>
#include <stdio.h>
#include <gtk/gtk.h>

const char *getUserName()
{
uid_t uid = geteuid();
struct passwd *pw = getpwuid(uid);
if (pw)
{
return pw->pw_name;
}

return "";
}

static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_print ("Hello %s\n", getUserName());
}

static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *button_box;

window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (window), button_box);

button = gtk_button_new_with_label (getUserName());
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
gtk_container_add (GTK_CONTAINER (button_box), button);

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;

}

最佳答案

添加 /usr/lib/glib-2.0/include/到包含路径。

基本上有人想添加 pkg-config 的输出到 VSCode 包括。
要将输出转储到 shell,请使用:echo $(pkg-config --libs --cflags gtk+-3.0)
如果您想提供pkg-config作为 VSCode 任务参数,请参阅 this answer .
我很高兴使用这个 VSCode extension使用 GCC 和 Clang。
这是我的 gist to kick off coding GTK 3 in C with VSCode.

快乐黑客!

关于c - 如何在 Visual Studio 代码中添加 gtk 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56978097/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com