我刚刚开始在Ubuntu中使用eclipse cdt和gtk学习C ++编程。
我能够安装和配置的软件包是:
我试图运行一个示例程序:
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
int main (int argc, char *argv[]) {
GtkWidget *window;
gtk_init (&amp;argc, &amp;argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), &quot;Window :-)&quot;);
g_signal_connect (window, &quot;destroy&quot;, G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
但我仍然收到错误“未解决的包含:”
答案 0 :(得分:1)
在终端中运行
pkg-config --cflags gtk+-3.0
并将输出放在&#34;编译器标志&#34;在eclipse的设置中的某个地方。
跑
pkg-config --libs gtk+-3.0
并将此命令的输出放在&#34;链接器标志&#34;领域。除非您真的是交叉编译,否则不要使用交叉编译器设置。只要你的代码是正确的,这就应该编译。
答案 1 :(得分:0)
有两个问题,
我没有注意到,但我附加的代码有几个问题 有一些奇怪的符号,我把它改成了这个:
res = original_string
delta = 0
# to keep things simple, assume replacements just contains objects which have start, end indices and replacements
replacements.each do |r|
old_str = original_str[r.start_offset .. r.end_offset]
new_str = r.replacement
res[r.start_offset + delta .. r.end_offset + delta] = new_str
delta += new_str.size - old_str.size
end
int main(int argc,char * argv []){ GtkWidget *窗口;
/// <summary>
/// This class provides dynamic size labels, i.e. as the text grows lable width will grow with it.
/// </summary>
public partial class AutoSizeLabel : UserControl
{
private string _strText;
private const int padding = 10;
public AutoSizeLabel()
{
InitializeComponent();
}
public override string Text
{
get
{
return _strText;
}
set
{
_strText = value;
Refresh();
}
}
protected override void OnPaint(PaintEventArgs pe)
{
SizeF size = pe.Graphics.MeasureString(this.Text, this.Font);
this.Size = new Size((int)size.Width + padding, this.Height);
if (this.Text.Length > 0)
{
pe.Graphics.DrawString(this.Text,
this.Font,
new SolidBrush(this.ForeColor),
(this.ClientSize.Width - size.Width) / 2,
(this.ClientSize.Height - size.Height) / 2);
}
// Calling the base class OnPaint
base.OnPaint(pe);
}
}
}