首页 > 代码库 > Ubuntu下在Eclipse IDE for C/C++ Developes中如何运行C语言的GTK程序?
Ubuntu下在Eclipse IDE for C/C++ Developes中如何运行C语言的GTK程序?
<p style="color: rgb(51, 51, 51); font-family: Arial; line-height: 25.99184799194336px; margin: 0.11cm 0.13cm; border: none; padding: 0cm;"><span style="line-height: 25.99184799194336px; background-color: rgb(240, 240, 240); font-family: 'DejaVu Serif', serif;"><span style="font-family: Arial, Verdana, sans-serif;"></span></span><pre name="code" class="cpp"><span style="line-height: 25.99184799194336px; white-space: pre-wrap; font-family: 'DejaVu Serif', serif;"><span style="font-family: Arial, Verdana, sans-serif;"></span></span><pre class="cjk" name="code" style="margin: 0.11cm 0.13cm; background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; color: rgb(51, 51, 51); line-height: 25.99184799194336px; border: none; padding: 0cm;"><span style="font-size: 13px;"><span style="font-family: Arial, Verdana, sans-serif;"> 按“Ubuntu下GTK的安装、编译和测试”(</span></span><span style="background-color: rgb(240, 240, 240); font-family: Arial, Verdana, sans-serif; font-size: 13px; line-height: 25.99184799194336px;">原文地址:</span><span style="font-family: Arial, Verdana, sans-serif;"><a target=_blank href=http://www.mamicode.com/"http://www.cnblogs.com/niocai/archive/2011/07/15/2107472.html" style="font-size: 13px;">http://www.cnblogs.com/niocai/archive/2011/07/15/2107472.html)所说步骤,终于成功安装了GTK,很开心,以为近一个月的困扰要解决了,但在Eclipse IDE for C/C++ Developes中一测试,出现找不到gtk/gtk.h头文件的错误。哭!
<span style="font-size: 13px;"><span style="font-family: Arial, Verdana, sans-serif;"> 又花了好些时间</span></span><span style="line-height: 25.99184799194336px; font-family: Arial, Verdana, sans-serif; font-size: 13px;">终于找到了Ubuntu下Eclipse的配置(</span><span style="line-height: 25.99184799194336px; font-size: 13px; font-family: Arial, Verdana, sans-serif; background-color: rgb(240, 240, 240);">原文地址:</span><a target=_blank href=http://www.mamicode.com/"http://blog.csdn.net/sunny2038/article/details/7082164" style="line-height: 25.99184799194336px; font-size: 13px; font-family: Arial, Verdana, sans-serif; background-color: rgb(240, 240, 240);">http://blog.csdn.net/sunny2038/article/details/7082164),终于能在Eclipse IDE for C/C++ Developers中找到gtk/gtk.h头文件了,以为终于熬出头了,不料测试一下,居然出来成百上千的错误,主要是类似于以下的错误和警告(g.c是源文件名):
<pre name="code" class="plain">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’ ……
好些头文件都有类似错误,百度无果,又没招了,该如何是好?恳求大牛帮忙……焦急等待中!!!
<pre class="cjk" name="code" style="font-size:14px; margin: 0.11cm 0.13cm; background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; color: rgb(51, 51, 51); line-height: 25.99184799194336px; border: none; padding: 0cm;">
----------------------------以下转载自:<span style="font-size:10px;font-size: 12px; color: rgb(0, 0, 0); text-decoration: none; font-family: 'Microsoft YaHei'; line-height: 30px;"><a target=_blank href=http://www.mamicode.com/"http://blog.csdn.net/sunny2038/article/details/7082164" style="font-size: 12px; color: rgb(0, 0, 0); text-decoration: none; font-family: 'Microsoft YaHei'; line-height: 30px;">Windows和Ubuntu11.10在Eclipse中配置C和GTK--------------------------------------------------
<span style="line-height: 25.99184799194336px; white-space: pre-wrap; font-family: 'DejaVu Serif', serif;"><span style="font-family: Arial, Verdana, sans-serif;"></span></span><pre class="cjk" name="code" style="margin: 0.11cm 0.13cm; background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; color: rgb(51, 51, 51); line-height: 25.99184799194336px; border: none; padding: 0cm;"><span style="font-size:14px;"></span><span style="color: rgb(51, 51, 51); font-size: 13.913043975830078px; line-height: 25.99184799194336px; font-family: 'DejaVu Serif', serif;"><span style="font-family: Arial, Verdana, sans-serif;"><span style="font-size: 13pt;"><strong>Ubuntu</strong></span></span></span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 13.913043975830078px; line-height: 25.99184799194336px;"><span style="font-family: Arial, Verdana, sans-serif;"><span style="font-size: 13pt;"><strong>下在</strong></span></span><span style="font-family: 'DejaVu Serif', serif;"><span style="font-family: Arial, Verdana, sans-serif;"><span style="font-size: 13pt;"><strong>Eclipse</strong></span></span></span></span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 13.913043975830078px; line-height: 25.99184799194336px;"><span style="font-family: Arial, Verdana, sans-serif;"><span style="font-size: 13pt;"><strong>中运行</strong></span></span><span style="font-family: 'DejaVu Serif', serif;"><span style="font-family: Arial, Verdana, sans-serif;"><span style="font-size: 13pt;"><strong>C</strong></span></span></span></span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 13.913043975830078px; line-height: 25.99184799194336px;"><span style="font-family: Arial, Verdana, sans-serif;"><span style="font-size: 13pt;"><strong>语言的</strong></span></span><span style="font-family: 'DejaVu Serif', serif;"><span style="font-family: Arial, Verdana, sans-serif;"><span style="font-size: 13pt;"><strong>GTK</strong></span></span></span></span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 13.913043975830078px; line-height: 25.99184799194336px;"><span style="font-family: Arial, Verdana, sans-serif;"><span style="font-size: 13pt;"><strong>程序</strong></span></span></span><span style="font-size:14px;"></span>
<span style="line-height: 25.99184799194336px; white-space: pre-wrap; font-family: 'DejaVu Serif', serif;"><span style="font-family: Arial, Verdana, sans-serif;">1</span></span><span style="line-height: 25.99184799194336px; white-space: pre-wrap; font-family: Arial, Verdana, sans-serif;">、下载相关的包</span>
<span style="font-size: 13px;"> <span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">sudo apt-get install gnome-core-devel build-essential libgtk2.0-dev libgtk2.0-doc</span></span></span>
<span style="font-size: 13px;"><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;"><strong>2</strong></span></span><span style="font-family: Arial, Verdana, sans-serif;"><strong>、测试代码</strong></span></span>
<span style="font-size: 13px;"> <span style="font-family: Arial, Verdana, sans-serif;">打开</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Eclipse</span></span><span style="font-family: Arial, Verdana, sans-serif;">,新建——</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">C Project——</span></span><span style="font-family: Arial, Verdana, sans-serif;">输入</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Project name</span></span><span style="font-family: Arial, Verdana, sans-serif;">,并选择</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Executable</span></span><span style="font-family: Arial, Verdana, sans-serif;">中的</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Hello World ANSI C Project</span></span><span style="font-family: Arial, Verdana, sans-serif;">,默认会选择</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Linux GCC</span></span><span style="font-family: Arial, Verdana, sans-serif;">的</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Toolchains</span></span><span style="font-family: Arial, Verdana, sans-serif;">,点击</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Finish——</span></span><span style="font-family: Arial, Verdana, sans-serif;">这时会打开一个</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Hello World</span></span><span style="font-family: Arial, Verdana, sans-serif;">的示例代码——将其中哦功能的代码换成下面的测试代码。(其实完全可以不用</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Hello World</span></span><span style="font-family: Arial, Verdana, sans-serif;">模版,这里只是简化过程。)</span></span>
#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; }
3、配置Eclipse
<span style="font-size: 13px;"> <span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">(1)</span></span><span style="font-family: Arial, Verdana, sans-serif;">选中</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">gtk</span></span><span style="font-family: Arial, Verdana, sans-serif;">项目,在菜单栏点击</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Project——Properties——C/C++ Build——Settings——GCC C Compiler——Miscellaneous</span></span><span style="font-family: Arial, Verdana, sans-serif;">,在</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Other flags</span></span><span style="font-family: Arial, Verdana, sans-serif;">中加入</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">`pkg-config –cflags gtk+-2.0`</span></span></span>
<span style="font-size: 13px;"> <span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">(2)</span></span><span style="font-family: Arial, Verdana, sans-serif;">在同一个对话框中,选择</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">GCC C Linker——Miscellaneous</span></span><span style="font-family: Arial, Verdana, sans-serif;">,在</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">Linker flags</span></span><span style="font-family: Arial, Verdana, sans-serif;">中加入</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">`pkg-config –libs gtk+-2.0`</span></span></span>
<span style="font-size: 13px;"> <span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;"><strong>(3)</strong></span></span><span style="font-family: Arial, Verdana, sans-serif;"><strong>选中</strong></span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;"><strong>GCC C Linker</strong></span></span><span style="font-family: Arial, Verdana, sans-serif;"><strong>,在右边的</strong></span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;"><strong>Command line pattern</strong></span></span><span style="font-family: Arial, Verdana, sans-serif;"><strong>里面的</strong></span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;"><strong>${INPUTS} </strong></span></span><span style="font-family: Arial, Verdana, sans-serif;"><strong>调到</strong></span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;"><strong>${COMMAND}</strong></span></span><span style="font-family: Arial, Verdana, sans-serif;"><strong>后面,如:</strong></span> <span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;"><strong>${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}</strong></span></span></span>
<span style="font-size: 13px;"> <span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">(4)</span></span><span style="font-family: Arial, Verdana, sans-serif;">在</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">GCC C Compiler——Includes</span></span><span style="font-family: Arial, Verdana, sans-serif;">中,加入</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">/usr/include/gtk-2.0 </span></span><span style="font-family: Arial, Verdana, sans-serif;">和 </span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">/usr/include/glib-2.0</span></span><span style="font-family: Arial, Verdana, sans-serif;">,可以消除</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">gtk.h unresolved</span></span><span style="font-family: Arial, Verdana, sans-serif;">的警告,同时在程序中使用</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">gtk</span></span><span style="font-family: Arial, Verdana, sans-serif;">的函数,会出现智能提示。</span></span>
<span style="font-size: 13px;"> <span style="font-family: Arial, Verdana, sans-serif;">经过以上步骤,一个</span><span style="font-family: 'DejaVu Sans Mono', monospace;"><span style="font-family: Arial, Verdana, sans-serif;">GTK</span></span><span style="font-family: Arial, Verdana, sans-serif;">程序就能运行出来了。</span></span>
Ubuntu下在Eclipse IDE for C/C++ Developes中如何运行C语言的GTK程序?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。