您的位置:首页 > 其它

Window下GTK开发环境搭建/Code::Blocks开发环境搭建/GLib程序测试

2010-05-20 21:12 676 查看
Window下GTK开发环境搭建

1. 首先安装Code::Blocks IDE
http://www.codeblocks.org/downloads/5#linux 下载 codeblocks-8.02mingw-setup.exe

或者直接使用链接
http://downloads.sourceforge.net/project/codeblocks/Binaries/8.02/codeblocks-8.02mingw-setup.exe?use_mirror=ncu
点击安装 (注意:安装路径不要有空格)

如何安装中文补丁见文:http://www.d2school.com/codeblocks/doc/setup.php

安装完成后,运行软件,Tools->Compiler and debugger settings->Toolchain executables

点击 auto-detect 这个按钮 它自动检测到gcc编译器

2.下载 gtk+-bundle_2.20.0-20100406_win32.zip 包

下载主页:http://www.gtk.org/download-windows.html

下载路径:http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.20/gtk+-bundle_2.20.0-20100406_win32.zip

3.解压gtk+-bundle_2.20.0-20100406_win32.zip 到C:/Program Files/gtk

4.添加 gtk的bin目录path到系统环境变量:我这里是将C:/Program Files/gtk/bin添加到path中

5.进入Code::Blocks, new project-->gtk project-->输入工程名:gtk_test-->选择gtk sdk路径:C:/Program Files/gtk

工程会自动创建一个程序hello实例,点击编译和运行就可以看到一个弹出的窗口了

6. Glib程序测试

#include <glib.h>

int main(int argc, char* argv[])

{

GRand *rand;

GTimer *timer;

gint n;

gint i, j;

gint x = 0;

rand = g_rand_new(); //创建随机数对象

for(n = 0; n < 20; n++)

{

//产生随机数并显示出来

g_print("%d/t",g_rand_int_range(rand, 1, 100));

}

g_print("/n");

g_rand_free(rand); //释放随机对象

//创建定时器

timer = g_timer_new();

g_timer_start(timer); //开始计时

for(i = 0; i < 10000; i++)

for(j = 0; j < 3000; j++)

x++; //累计

g_timer_stop(timer); //计时结束

//输出计时结果

g_print("%d/t all:%.2f seconds was used!/n", x, g_timer_elapsed(timer, NULL));

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: