本文介绍了如何编译gtk +应用程序的本机窗口(而不是X窗口)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设法使用cygwin编译了一个gtk +应用程序,但不幸的是使用这种方法,应用程序需要x windows运行才能启动。



编译我的gtk +应用程序在Windows上本机运行。



我已经在网上看到关于使用 -mno-cygwin 标志为 gcc ,但是似乎已被弃用?



我也看过这些postoveroverover,但它不清楚如果他们试图编译为X,或本机为Windows:





  • I have managed to compile a gtk+ application with cygwin, but unfortunately with this approach, the application needs x windows running to be able to startup.

    How can I compile my gtk+ application to run natively on windows.

    I have seen various posts online about using the -mno-cygwin flag to gcc, but that seems to have been deprecated?

    I have also seen these posts on stackoverflow, but its not clear if they are trying to compile for X, or natively for Windows:

    解决方案

    The application needs to be compiled using MinGW and not Cygwin.

    The full list of steps I followed:

    1) Download MinGW

    2) Install MinGW to a folder without spaces, e.g. to c:\MinGW.

    3) Download gtk+. Even though my machine is 64bit, I went for the 32 bit download of gtk+ because compatibility warnings on the 64bit download page. The GTK+ Win32 downloads are here. I went for the all-in-one version.

    4) Extract gtk+ to a folder without spaces, e.g. c:\gtk

    5) If you don't already have an application, you can use the gtk+ hello world source code. Save this to a folder, e.g. c:\myapp\

    6) Open a windows command prompt and cd to the folder in step 5. E.g.

    cd c:\myapp

    7) In the command window, add your MinGW folder to the windows PATH, e.g.

    c:\myapp> set PATH=c:\gtk\bin;%PATH%

    8) In the command window, add your gtk+ folder to the windows PATH, e.g.

    c:\myapp> set PATH=c:\gtk\bin;%PATH%

    9) Create a script to compile your application, e.g.

    C:\myapp> C:\MinGW\msys\1.0\bin\bash.exe -c "echo gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` > compile.bat"
    

    Note that I had to give the full path to bash.exe. For some reason adding c:\MinGW\msys\1.0\bin to the PATH and just using bash.exe didn't work for me.

    10) compile your application with compile.bat, e.g.

    c:\myapp> compile.bat

    12) execute your application, e.g.

    c:\myapp> helloworld.exe


    EDIT:

    For step 9, we are just creating a gcc command to compile gtk+ with the correct include and library option settings.

    This is the contents of compile.bat that got generated for me:

    gcc -Wall -g helloworld.c -o helloworld -mms-bitfields -Ic:/DEV/gtk224/include/gtk-2.0 -Ic:/DEV/gtk224/lib/gtk-2.0/include -Ic:/DEV/gtk224/include/atk-1.0 -Ic:/DEV/gtk224/include/cairo -Ic:/DEV/gtk224/include/gdk-pixbuf-2.0 -Ic:/DEV/gtk224/include/pango-1.0 -Ic:/DEV/gtk224/include/glib-2.0 -Ic:/DEV/gtk224/lib/glib-2.0/include -Ic:/DEV/gtk224/include -Ic:/DEV/gtk224/include/freetype2 -Ic:/DEV/gtk224/include/libpng14 -Lc:/DEV/gtk224/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
    

    Of which, the include options created by pkg-config --cflags gtk+-2.0:

    -mms-bitfields -Ic:/DEV/gtk224/include/gtk-2.0 -Ic:/DEV/gtk224/lib/gtk-2.0/include
       -Ic:/DEV/gtk224/include/atk-1.0 -Ic:/DEV/gtk224/include/cairo
       -Ic:/DEV/gtk224/include/gdk-pixbuf-2.0 -Ic:/DEV/gtk224/include/pango-1.0
       -Ic:/DEV/gtk224/include/glib-2.0 -Ic:/DEV/gtk224/lib/glib-2.0/include
       -Ic:/DEV/gtk224/include -Ic:/DEV/gtk224/include/freetype2
       -Ic:/DEV/gtk224/include/libpng14
    

    (note I have put in line breaks above to improve readability on stackoverflow)

    Notice that pkg-config --cflags gtk+-2.0 has put the full path of my gtk+ include files (c:/DEV/gtk224/include/).

    And the library options generated by pkg-config --libs gtk+-2.0:

    -Lc:/DEV/gtk224/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0
       -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0
       -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
    

    (note I have put in line breaks above to improve readability on stackoverflow)

    Notice that pkg-config --libs gtk+-2.0 has put the full path of my gtk library folder (c:/DEV/gtk224/lib).

    For more information on pkg-config see the GTK+ documentation

    这篇关于如何编译gtk +应用程序的本机窗口(而不是X窗口)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:36