-
首先要有非常好用的clion工具
-
clion选择编译器,我这里选择了
MinGW
file
->settings
->ToolChains
->点击+号
(我这里自动识别了)->OK
-
并且去配置
cmake
生成debug
和release
- debug是默认有的,release我点加号的时候也自动识别了
- debug是默认有的,release我点加号的时候也自动识别了
-
新建一个c++工程
file
->new project
->c++ project
并得到目录结构
-
-
搭建开发环境
-
下载
GTK+ 3.6.4 Bundle for Windows
网址
http://www.tarnyko.net/dl/gtk.htm
-
-
解压后得到目录
gtk+-3xxx
- 我这里放到了
H:\mysoft\clion\clionWorkSpace
目录下 - 下面有
bin
,include
和lib
之类的目录
- bin目录下的
dll
是要放在编译好.exe
文件的同级目录
下,.exe
文件才能运行(windows下优先搜索当前文件夹下的dll)
- 我这里放到了
-
把
include
和lib
里的东西添加到cmakelists.txt
(使用cmake构建)-
H:\mysoft\clion\clionWorkSpace
部分需要自己修改哦 -
include
的include_directories( H:/mysoft/clion/clionWorkSpace/gtk+364/include H:/mysoft/clion/clionWorkSpace/gtk+364/include/gtk-3.0 H:/mysoft/clion/clionWorkSpace/gtk+364/include/cairo H:/mysoft/clion/clionWorkSpace/gtk+364/include/gdk H:/mysoft/clion/clionWorkSpace/gtk+364/include/glib-2.0 H:/mysoft/clion/clionWorkSpace/gtk+364/include/pango-1.0 H:/mysoft/clion/clionWorkSpace/gtk+364/include/atk-1.0 H:/mysoft/clion/clionWorkSpace/gtk+364/include/gdk-pixbuf-2.0 H:/mysoft/clion/clionWorkSpace/gtk+364/lib/glib-2.0/include H:/mysoft/clion/clionWorkSpace/gtk+364/lib/gtk-3.0/include )
-
lib
的所有.a
文件link_libraries( H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libatk-1.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libcairo-gobject.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libcairo-script-interpreter.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libcairo.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libcroco-0.6.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libffi.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libfontconfig.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libfreetype.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libgailutil-3.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libgdk-3.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libgdk_pixbuf-2.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libgio-2.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libglib-2.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libgmodule-2.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libgobject-2.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libgthread-2.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libgtk-3.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libjasper.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libjpeg.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/liblzma.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libpango-1.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libpangocairo-1.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libpangoft2-1.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libpangowin32-1.0.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libpixman-1.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libpng.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libpng15.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/librsvg-2.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libtiff.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libtiffxx.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libxml2.dll.a H:/mysoft/clion/clionWorkSpace/gtk+364/lib/libz.dll.a )
- 使用
Mingw
编译好.exe
后,双击运行时会弹出黑窗口控制台,在cmakelists.txt
里添加以下代码可消除黑窗口# mingw消除黑窗口 C++工程 set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -mwindows) # mingw消除黑窗口 C 工程 # set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mwindows)
-
-
编写helloworld代码,把以下代码拷贝到
main.cpp
里面#include <gtk/gtk.h> #include <string.h> int main(int argc, char **argv) { GtkWidget *window; // 要先init gtk_init(&argc, &argv); // 才能new window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(window, "delete_event", gtk_main_quit, NULL); gtk_widget_show_all(window); gtk_main(); return 0; }
-
点击clion的小绿锤子编译(当然是可选的)得到
.exe
可执行文件 -
把可执行文件和那些
.dll
放到同级目录下,双击运行即可(我还不知道如何把他们打包成单个可执行文件)
相关文章
- 03-08Three.js 学习笔记之一 Helloworld(翻译)
- 03-08“黑马旅游网”综合案例-学习笔记01【准备工作】
- 03-08BGFX学习笔记01
- 03-08Mybatis学习笔记 - 01
- 03-08gtk学习笔记01 helloworld
- 03-08学习airtest+poce笔记01
- 03-08【11-01】Sublime text 学习笔记
- 03-08前端学习笔记Day01
- 03-08day01:学习笔记
- 03-08react学习笔记_01-jsx