gpt4 book ai didi

C++ GTK制作MinGW报错简单程序

转载 作者:行者123 更新时间:2023-11-28 08:23:39 24 4
gpt4 key购买 nike

我真的需要帮助来获得使用 MinGW 运行的 C++ 中的简单 GTK 程序。这是我的程序:

# Makefile for Hello World Program (lab0).

all: lab0

lab0: lab0.o
g++ -Wall lab0.o -o lab0 -L C:/Users/Vic/Desktop/MinGW/lib -lgtk

lab0.o: lab0.c
g++ -Wall -I C:/Users/Vic/Desktop/MinGW/include/gtk-2.0/gtk -c lab0.c -o lab0.o

程序:

#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;

gtk_init (&argc, &argv);

/* create the main, top level, window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

/* give it the title */
gtk_window_set_title (GTK_WINDOW (window), "Hello World");

/* Connect the destroy signal of the window to gtk_main_quit
* When the window is about to be destroyed we get a notification and
* stop the main GTK+ loop
*/
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

/* Create the "Hello, World" label */
label = gtk_label_new ("Hello, World");

/* and insert it into the main window */
gtk_container_add (GTK_CONTAINER (window), label);

/* make sure that everything, window and label, are visible */
gtk_widget_show_all (window);

/* start the main loop, and let it rest there until the application is closed */
gtk_main ();

return 0;
}

当我使用 minGW 编译它时,我得到了这个错误:

g++ -Wall lab0.o -o lab0 -LC:/users/vic/desktop/mingw/lib -lgtk
/bin/Id: cannot find -lgtk
collect2: Id returned 1 exit status
make: *** [lab0] Error 1

我需要解决这个问题,我需要弄清楚如何从我的 makefile 运行 gtk。

最佳答案

理想情况下,您可以使用 pkg-config 来帮助您找到 header 和库路径:

g++ -Wall lab0.o -o lab0 `pkg-config --cflags --libs gtk+-win32-2.0`

或者只是库路径:

g++ -Wall lab0.o -o lab0 -LC:/users/vic/desktop/mingw/lib -lgtk `pkg-config --libs gtk+-win32-2.0`

关于C++ GTK制作MinGW报错简单程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4901884/

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