看板 C_and_CPP 關於我們 聯絡資訊
開發平台(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://www.ptt.cc/bbs/C_and_CPP/M.1519847521.A.AD2.html
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
Lipraxde: startxwin,那篇文章不是有寫嗎... 03/01 14:15
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
Lipraxde: 改用Mingw,或者Qt 03/01 15:19
wei115: 好吧QQ 03/01 15:36
wei115: 謝謝 03/01 15:36
rehon: 改用msys2 這比cygwin好用多了 03/01 20:18
rehon: 編譯環境參考 https://wiki.geany.org/howtos/win32/msys2 03/01 20:18
謝謝,改用msys2了,但目前變成設定msys2出問題了....
joe820730: 用VcXsrv搭建XWindow,然後term底下輸入: 03/01 23:25
joe820730: export DISPLAY=127.0.0.1:0 03/01 23:25
joe820730: 不過如果真要弄GTK還是用Linux吧,畢竟GTK生於Linux 03/01 23:30
joe820730: 喔等等,你應該看這篇:https://goo.gl/3G9J1L 03/01 23:35
joe820730: 用cygwin跑GTK的話會接到Xwindow,直接用MinGW才會直接 03/01 23:36
joe820730: 直接使用Windows的視窗 03/01 23:37
恩恩,感謝,回去查了才知道 MinGW的gcc 和 cygwin的gcc 有差別QQ,目前改用MSYS2中
uranusjr: GTK 在 Windows 上就是個悲劇, 別自找麻煩 03/02 18:32
為什麼是悲劇阿?
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