作者wei115 (ㄎㄎ)
看板C_and_CPP
标题[问题] cygwin GTK环境搭建
时间Thu Mar 1 03:51:57 2018
开发平台(Platform): (Ex: Win10, Linux, ...)
Windows 7 + cygwin
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
gcc 6.4.0
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
gtk3.0
问题(Question):
一直无法成功建立GTK的编译环境,我在安装介面搜寻GTK 把Devel下的选项全部安装,也
安装xinit了
但是在使用gcc编译时他却显示gtk/gtk.h : no such file or directory
使用 pkg-config gtk+-3.0--cflags --libs
则显示
Package gtk+-3.0--cflags was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-3.0--cflags.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-3.0--cflags' found
但使用 pkg-config gtk+-3.0 --libs
则会显示
-lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject
-lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl
预期的正确结果(Expected Output):
正常编译GTK程式
错误结果(Wrong Output):
gtk/gtk.h : no such file or directory
程式码(Code):(请善用置底文网页, 记得排版,禁止使用图档)
#include <gtk/gtk.h> //关联图形库
int main(int argc, char* argv[])
{
GtkWidget* window; //创建图形窗口
GtkWidget* label; //创建
gtk_init(&argc, &argv); //初始化图形驱动
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); //创建图形顶层画布
label = gtk_label_new("Hello World."); //创建新的标签
gtk_container_add(GTK_CONTAINER(window), label); //关联画布和标签
gtk_widget_show_all(window); //显示驱动程序
gtk_main(); //显示画面
return 0;
}
补充说明(Supplement):
参考以下教学
http://blog.csdn.net/pjzck/article/details/51205202
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.126.109.77
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1519847521.A.AD2.html
1F:→ Lipraxde: gtk+-3.0 --cflags,中间有个空白 03/01 06:09
你好,感谢
将编译参数改为
gcc -Wall hello.c -o Hello `pkg-config gtk+-3.0 --cflags --libs`
便可正常边译
但在执行时却显示
Gtk-WARNING **: cannot open display:
我猜是Xwindow的参数设定错误
但目前还没有解答(绝赞google中)
如果有解决方法还请帮忙解惑<(_ _)>
话说有没有办法不靠Xwindow直接执行的方法(windows下)
※ 编辑: wei115 (101.138.162.172), 03/01/2018 13:46:06
2F:→ Lipraxde: startxwin,那篇文章不是有写吗... 03/01 14:15
3F:→ Lipraxde: 乖乖用linux会帮你省很多麻烦 03/01 14:15
用了startwin但没办法,执行後左下角出现X的图示,但右键後却没教学说的
Terminal选项
至於linux嘛.....图形模式比windows难QQ
而且我想写windows的GUI程式.
以下log
(II) xorg.conf is not supported
(II) See
http://x.cygwin.com/docs/faq/cygwin-x-faq.html for more information
LoadPreferences: /home/weinb/.XWinrc not found
LoadPreferences: Loading /etc/X11/system.XWinrc
LoadPreferences: Done parsing the configuration file...
winDetectSupportedEngines - RemoteSession: no
winDetectSupportedEngines - DirectDraw4 installed, allowing ShadowDDNL
winDetectSupportedEngines - Returning, supported engines 00000005
winSetEngine - Multi Window or Rootless => ShadowGDI
winScreenInit - Using Windows display depth of 32 bits per pixel
winAllocateFBShadowGDI - Creating DIB with width: 1366 height: 768 depth: 32
winFinishScreenInitFB - Masks: 00ff0000 0000ff00 000000ff
winInitVisualsShadowGDI - Masks 00ff0000 0000ff00 000000ff BPRGB 8 d 24 bpp 32
MIT-SHM extension disabled due to lack of kernel support
XFree86-Bigfont extension local-client optimization disabled due to lack of
shared memory support in the kernel
glWinSelectGLimplementation: Loaded 'cygnativeGLthunk.dll'
(II) AIGLX: Testing pixelFormatIndex 1
GL_VERSION: 3.1.0 - Build 9.17.10.4229
GL_VENDOR: Intel
GL_RENDERER: Intel(R) HD Graphics 3000
(II) GLX: enabled GLX_SGI_make_current_read
(II) GLX: enabled GLX_SGI_swap_control
(II) GLX: enabled GLX_MESA_swap_control
(II) GLX: enabled GLX_SGIX_pbuffer
(II) GLX: enabled GLX_ARB_multisample
(II) GLX: enabled GLX_SGIS_multisample
(II) GLX: enabled GLX_ARB_fbconfig_float
(II) GLX: enabled GLX_EXT_fbconfig_packed_float
(II) GLX: enabled GLX_ARB_create_context
(II) GLX: enabled GLX_ARB_framebuffer_sRGB
(II) AIGLX: enabled GLX_MESA_copy_sub_buffer
(II) 60 pixel formats reported by wglGetPixelFormatAttribivARB
(II) 24 fbConfigs
(II) ignored pixel formats: 0 not OpenGL, 0 unknown pixel type, 36
unaccelerated
(II) GLX: Initialized Win32 native WGL GL provider for screen 0
winPointerWarpCursor - Discarding first warp: 683 384
(--) 5 mouse buttons found
(--) Setting autorepeat to delay=500, rate=31
(--) Windows keyboard layout: "00000404" (00000404) "Chinese (Traditional) -
US Keyboard", type 7
(--) Found matching XKB configuration "Chinese (Traditional)"
(--) Model = "pc105" Layout = "cn" Variant = "none" Options = "none"
Rules = "base" Model = "pc105" Layout = "cn" Variant = "none" Options = "none"
winInitMultiWindowWM - DISPLAY=:0.0
winMultiWindowXMsgProc - DISPLAY=:0.0
cat: '': No such file or directory
winInitMultiWindowWM - xcb_connect () returned and successfully opened the
display.
winProcEstablishConnection - winInitClipboard returned.
winClipboardThreadProc - DISPLAY=:0.0
winMultiWindowXMsgProc - xcb_connect() returned and successfully opened the
display.
Using Composite redirection
OS maintains clipboard viewer chain: yes
winClipboardProc - XOpenDisplay () returned and successfully opened the
display.
LoadPreferences: /home/weinb/.XWinrc not found
LoadPreferences: Loading /etc/X11/system.XWinrc
LoadPreferences: Done parsing the configuration file...
SetupSysMenu: GetSystemMenu() failed for HWND 0xe802ce
SetupSysMenu: GetSystemMenu() failed for HWND 0xc0764
LoadPreferences: /home/weinb/.XWinrc not found
LoadPreferences: Loading /etc/X11/system.XWinrc
LoadPreferences: Done parsing the configuration file...
SetupSysMenu: GetSystemMenu() failed for HWND 0xe802ce
SetupSysMenu: GetSystemMenu() failed for HWND 0xc0764
※ 编辑: wei115 (120.109.128.225), 03/01/2018 14:34:09
4F:→ Lipraxde: 改用Mingw,或者Qt 03/01 15:19
5F:→ wei115: 好吧QQ 03/01 15:36
6F:→ wei115: 谢谢 03/01 15:36
7F:推 rehon: 改用msys2 这比cygwin好用多了 03/01 20:18
谢谢,改用msys2了,但目前变成设定msys2出问题了....
9F:→ joe820730: 用VcXsrv搭建XWindow,然後term底下输入: 03/01 23:25
10F:→ joe820730: export DISPLAY=127.0.0.1:0 03/01 23:25
11F:→ joe820730: 不过如果真要弄GTK还是用Linux吧,毕竟GTK生於Linux 03/01 23:30
13F:→ joe820730: 用cygwin跑GTK的话会接到Xwindow,直接用MinGW才会直接 03/01 23:36
14F:→ joe820730: 直接使用Windows的视窗 03/01 23:37
恩恩,感谢,回去查了才知道 MinGW的gcc 和 cygwin的gcc 有差别QQ,目前改用MSYS2中
15F:→ uranusjr: GTK 在 Windows 上就是个悲剧, 别自找麻烦 03/02 18:32
为什麽是悲剧阿?
16F:推 xvid: 可以考虑改用 Qt 03/03 20:53
我想用C写视窗.....
※ 编辑: wei115 (59.126.109.77), 03/03/2018 21:12:16
喔喔,感谢各位大大
终於搞好了,用MSYS2安装GTK好容易阿阿阿阿(虽然装MSYS2环境的时候发生不少问题)
话说我终於搞清楚cygwin和MinGW的差别了
以前一直以为MinGW只是把编译相关的东西从cygwin独立出来
结果不是,还有一些引用函式库的不同(cygwin POSIX, MinGW WIN32)
好八,看来可以开始hello, world惹QQ
※ 编辑: wei115 (59.126.109.77), 03/04/2018 03:19:04