1.下载安装codeblocks
http://www.codeblocks.org/
http://sourceforge.net/projects/codeblocks/files/Binaries/17.12/Windows/codeblocks-17.12-nosetup.zip
2.下载安装msys64
http://www.msys2.org/
下载和配置msys2:
从http://msys2.github.io/下载安装包,并安装;
配置软件源(官方源速度较慢)
需要修改安装目录下,/etc/pacman.d 文件夹中的mirrorlist.msys,mirrorlist.mingw64,mirrorlist.mingw32 三个文件,
分别在文件开始处添加
mirrorlist.msys:
##中国科学技术大学开源软件镜像
Server = http://mirrors.ustc.edu.cn/msys2/REPOS/MSYS2/$arch
##北京理工大学镜像
Server = http://mirror.bit.edu.cn/msys2/REPOS/MSYS2/$arch
mirrorlist.mingw64:
##中国科学技术大学开源软件镜像
Server = http://mirrors.ustc.edu.cn/msys2/REPOS/MINGW/x86_64
##北京理工大学镜像
Server = http://mirror.bit.edu.cn/msys2/REPOS/MINGW/x86_64
mirrorlist.mingw32:
##中国科学技术大学开源软件镜像
Server = http://mirrors.ustc.edu.cn/msys2/REPOS/MINGW/i686
##北京理工大学镜像
Server = http://mirror.bit.edu.cn/msys2/REPOS/MINGW/i686
安装工具链和库:
下面是64位系统,如果是32位系统,则把x86_64 改为 i686
更新整个系统
pacman -Syu
安装工具链
pacman -S mingw-w64-x86_64-toolchain
如果提示冲突,则使用
pacman -S --force mingw-w64-x86_64-toolchain
开发的各种辅助工具
pacman -S base-devel
安装gtk+3的库
pacman -S --force mingw-w64-x86_64-gtk3
设置系统环境变量
set PATH=%PATH%;D:\DevelopmentEnvironment\Softwares\msys64\mingw64\bin
3.codeblocks配置gtk3
编辑share\CodeBlocks\templates\wizard\config.script:
RegisterWizard(wizProject, _T("gtk"), _T("GTK+ project"), _T("GUI"));
+ RegisterWizard(wizProject, _T("gtk3"), _T("GTK3 project"), _T("GUI"));
拷贝share\CodeBlocks\templates\wizard\gtk目录(包含所有文件)到share\CodeBlocks\templates\wizard\gtk3,
编辑share\CodeBlocks\templates\wizard\gtk3\wizard.script:
8 GtkPathDefault <- _T("$(#gtk)");
--->>>
GtkPathDefault <- _T("$(#gtk3)");
9 GtkPathDefaultInc <- _T("$(#gtk.include)");
-->>>
GtkPathDefaultInc <- _T("$(#gtk3.include)");
10 GtkPathDefaultLib <- _T("$(#gtk.lib)");
--->>>
GtkPathDefaultLib <- _T("$(#gtk3.lib)");
...
57 if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))
--->>>
if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-3.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include"))
...
64 if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-win32-2.0"), _T("GTK's")))
--->>>
if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-3"), _T("GTK's")))
...
116 project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-2.0"));
--->>>
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-3.0"));
...
123 project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH + _T("include"));
--->>>
project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-3.0") + wxFILE_SEP_PATH + _T("include"));
...
131 project.AddLinkLib(_T("gtk-win32-2.0"));
--->>>
project.AddLinkLib(_T("gtk-3"));
...
147 project.AddCompilerOption(_T("`pkg-config gtk+-2.0 --cflags`"));
--->>>
project.AddCompilerOption(_T("`pkg-config gtk+-3.0 --cflags`"));
148 project.AddLinkerOption(_T("`pkg-config gtk+-2.0 --libs`"));
--->>>
project.AddLinkerOption(_T("`pkg-config gtk+-3.0 --libs`"))
4.codeblocks配置gcc环境变量
[ settings->Compiler settings->Global compiler settings ]:
Toolchain executables:
安装路径\msys64\mingw64
5.codeblocks配置全局gtk3环境变量
[ settings->Global Variable Editor ]:
gtk3:
base=安装路径\msys64\mingw64
include=安装路径\msys64\mingw64\include
lib=安装路径\msys64\mingw64\lib
6.创建gtk3例子
编译运行。