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

发布于 2024-10-15 16:46:50 字数 1617 浏览 0 评论 0原文

我真的需要帮助来使用 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。

I really need help on getting a simple GTK program in c++ running using MinGW. Here's my program:

# 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

Program:

#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;
 }

when i compile this using minGW i get this error:

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

I need to fix this problem and I need to figure out how to run gtk from my makefile.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏雨凉 2024-10-22 16:46:50

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

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`

Ideally, you would use pkg-config to help you find the header and library paths:

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

Or just the library path:

g++ -Wall lab0.o -o lab0 -LC:/users/vic/desktop/mingw/lib -lgtk `pkg-config --libs gtk+-win32-2.0`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文