打印

gtk下的多线程出错。段错误?

gtk下的多线程出错。段错误?

使用的是gtk+-2.8.0。
编译的命令:gcc -g -W -Wall -o test test.c `pkg-config gtk+-2.0 --libs gthread --cflags`

段错误
[code:1]#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <glib.h>
#include <pthread.h>
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
  GtkWidget *window;

  g_thread_init(NULL);
  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_show(window);

  gdk_threads_enter();
  gtk_main();
  gdk_threads_leave();

  return(0);
}[/code:1]

TOP

[code:1]
g_thread_init(NULL);
#if GTK_MAJOR_VERSION == 2
    gdk_threads_init();
#endif
[/code:1]

TOP

谢谢你们。
不过还是不行,我看,应该是我安装的时候出错了,因为,只有多线程出错,其它的没有任何为题。我试试重装它。

TOP

--libs  gthread-2.0

TOP

gdk_threads_init()必须要加上

TOP

[quote:17269d1b8d="dzho002"]--libs  gthread-2.0[/quote]

非常感谢。加上-2.0就能用了,原来如此。我还以为是安装有错误呢。
也非常感谢大家的支持。再次谢谢。

TOP

你那个不是多线程,多线程要加一句gdk_flush ();
不是每朵花都能代表爱情,但是玫瑰做到了; 不是每个人都能让我想念,但是你做到了。

TOP