Ubuntu下在Eclipse IDE for C/C++ Developes中如何運行C語言的GTK程式?,developesgtk

來源:互聯網
上載者:User

Ubuntu下在Eclipse IDE for C/C++ Developes中如何運行C語言的GTK程式?,developesgtk

        按“Ubuntu下GTK的安裝、編譯和測試”(http://www.cnblogs.com/niocai/archive/2011/07/15/2107472.html)所說步驟,終於成功安裝了GTK,很開心,以為近一個月的困擾要解決了,但在Eclipse IDE for C/C++ Developes中一測試,出現找不到gtk/gtk.h標頭檔的錯誤。哭! 

        又花了好些時間終於找到了Ubuntu下Eclipse的配置(http://blog.csdn.net/sunny2038/article/details/7082164),終於能在Eclipse IDE for C/C++ Developers中找到gtk/gtk.h標頭檔了,以為終於熬出頭了,不料測試一下,居然出來成百上千的錯誤,主要是類似於以下的錯誤和警告(g.c是源檔案名稱):

In file included from /usr/include/gtk-2.0/gtk/gtk.h:170, from ../g.c:1:
/usr/include/gtk-2.0/gtk/gtkspinner.h:58: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gtk_spinner_get_type’
In file included from /usr/include/gtk-2.0/gtk/gtk.h:171,from ../g.c:1:
/usr/include/gtk-2.0/gtk/gtkstatusbar.h:63: warning: parameter names (without types) in function declaration
/usr/include/gtk-2.0/gtk/gtkstatusbar.h:63: error: field ‘GSEAL’ declared as a function
/usr/include/gtk-2.0/gtk/gtkstatusbar.h:65: warning: parameter names (without types) in function declaration
/usr/include/gtk-2.0/gtk/gtkstatusbar.h:65: error: bit-field ‘GSEAL’ has invalid type
/usr/include/gtk-2.0/gtk/gtkstatusbar.h:55: error: duplicate member ‘GSEAL’…

      好些標頭檔都有類似錯誤,百度無果,又沒招了,該如何是好?懇求大牛幫忙……焦急等待中!!!


---------------以下轉載自:Windows和Ubuntu11.10在Eclipse中配置C和GTK--------------------------------------------------
Ubuntu下在Eclipse中運行C語言的GTK程式
1、下載相關的包
        sudo apt-get install gnome-core-devel build-essential libgtk2.0-dev libgtk2.0-doc
2、測試代碼
        開啟Eclipse,建立——C Project——輸入Project name,並選擇Executable中的Hello World ANSI C Project,預設會選擇Linux GCC的Toolchains,點擊Finish——這時會開啟一個Hello World的範例程式碼——將其中哦功能的代碼換成下面的測試代碼。(其實完全可以不用Hello World模版,這裡只是簡化過程。)


<span style="font-size:14px;">#include <gtk/gtk.h> int main( int argc, char *argv[] ){         GtkWidget *window;        gtk_init (&argc, &argv);        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);        gtk_widget_show (window);        gtk_main ();        return 0; }</span>


3、配置Eclipse       
        (1)選中gtk項目,在功能表列點擊Project——Properties——C/C++ Build——Settings——GCC C Compiler——Miscellaneous,在Other flags中加入`pkg-config –cflags gtk+-2.0`
        (2)在同一個對話方塊中,選擇GCC C Linker——Miscellaneous,在Linker flags中加入`pkg-config –libs gtk+-2.0`
        (3)選中GCC C Linker,在右邊的Command line pattern裡面的${INPUTS} 調到${COMMAND}後面,如:${COMMAND}  ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}
        (4)在GCC C Compiler——Includes中,加入/usr/include/gtk-2.0 和 /usr/include/glib-2.0,可以消除gtk.h unresolved的警告,同時在程式中使用gtk的函數,會出現智能提示。
        經過以上步驟,一個GTK程式就能運行出來了。



ubuntu下C語言GTK使用者介面編程遇到問題了,協助

1) 編譯選項裡加上-g選項,就可以用gdb調試
2) 如果不用-o指定組建檔案,預設產生a.out,如果想產生可執行檔test,請用-o test
invalid cast from `GtkWindow' to `GtkEntry這句運行時警告的意思是你用了GTK_ENTRY(widget),但是widget其實不是gtk_new_entry建立的,實際上widget是一個GtkWindow對象
 
ubuntu下的C編程,GTK圖形開發,解釋

button[i]=gtk_button_new_with_label(temp[i]);
這句錯了,這個函數的原形是
gtk_button_new_with_label(char *),也就是參數是字串的,但你傳了一個字元給他,所以錯誤。
你應該這樣子。
char temp[15][2]={{'0',0x00},{'1',0x00},{'2',0x00},{'3',0x00},{'4',0x00},{'5',0x00},{'6',0x00},{'7',0x00},{'8',0x00},{'9',0x00},{'+',0x00},{'-',0x00},{'*',0x00},{'/',0x00},{'=',0x00}};

button[i]=gtk_button_new_with_label(temp[i]);
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.