Windows安装Xming:https://sourceforge.net/projects/xming/ (Xming过时很久未更新,可使用VcXsrv)
xming快捷方式: xming.exe :0 -clipboard -multiwindow -ac
Windows安装VcXsrv: https://sourceforge.net/projects/vcxsrv/
vcxsrv快捷方式: vcxsrv.exe :0 -clipboard -multiwindow -ac
特别注意:防火墙添加xming和vcxsrv例外(TCP通过即可)
Linux的环境参数设置可以放在~/.bashrc文件中,只要两行:
# Show app ui
#export DISPLAY=:0.0
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
export LIBGL_ALWAYS_INDIRECT=1
export NO_AT_BRIDGE=1
Debian:
sudo apt-get install build-essential
sudo apt-get install libgtk-3-dev
sudo apt-get install pkg-config
Ubuntu:
sudo apt-get install build-essential
sudo apt-get install gnome-devel gnome-devel-docs
Centos:
sudo yum -y install gtk3-devel gtk3-devel-docs
test.c
#include <gtk/gtk.h>
main(int argc,char *argv[])
{
GtkWidget *window;
GtkWidget *label;
char title[]="test";
char text[]="This is the test.";
gtk_init(&argc, &argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), title);
label=gtk_label_new(text);
gtk_container_add(GTK_CONTAINER(window), label);
gtk_widget_show(window);
gtk_widget_show(label);
gtk_main();
return 0;
}
编译:
gcc -o gtktest test.c pkg-config --cflags --libs gtk+-3.0
build.sh:
gcc $1 -o $2 `pkg-config --cflags --libs gtk+-3.0`
./build.sh test.c gtktest
./gtktest