Windows下用VScode编写ege图形库
- MinGw-w64
- 安装
- 安装ege
- 测试ege库
- 安装Visual Studio Code
- 配置Visual Studio Code
MinGw-w64
ege使用的是g++编译MinGw-w64就是Windows下比较出名的一款,当然可以用其他的,但本文使用MinGw-w64
安装
首先去MinGw-w64的下载页面:https://sourceforge.net/projects/mingw-w64/files/
下载压缩包
下载结束后,解压,将bin目录加到PATH环境变量中。
打开命令提示符输入
gcc -v
g++ -v
gdb -v
出现
等类似样子,就是正常安装MinGw-w64了,可以来写代码了。
安装ege
先从https://xege.org/install_and_config#xege_dl下载ege19.01_all.7z包
解压后得到
就对了。
-
将include目录下的一个文件夹和两个头文件复制粘贴到MinGw-w64放置目录的i686-w64-mingw32或者x86_64-w64-mingw32下的include目录下。
-
将lib目录下的mingw32或者是mingw64文件夹选择位数打开将里面的.a文件放到i686-w64-mingw32或者x86_64-w64-mingw32下的lib目录下。
至此ege库安装成功。
测试ege库
输入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <graphics.h> int main() { //初始化为640*480大小 initgraph(640, 480); //等待用户按键 getch(); //关闭图形界面 closegraph(); return 0; } |
保存为main.cpp文件。然后在cmd中进入保存文件夹,输入
32位
1 | g++ main.cpp -o ege.exe -lgraphics -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lgdiplus |
64位
1 | g++ main.cpp -o ege.exe -lgraphics64 -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lgdiplus |
在目录下出现ege.exe,不产生错误即为成功。
安装Visual Studio Code
下载安装程序后一路继续即可。
配置Visual Studio Code
- 打开VScode,安装C/C++和Code Running以及其他扩展。
- 进入工作目录,创建文件夹.vscode(不要忘了点)在文件中创建launch.json,
settings.json,tasks.json三个文件。 - launch.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | { // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "ege", //调试界面显示名称 "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", //可执行文件目录 "args": [], //额外命令行参数 "stopAtEntry": false, "cwd": "${workspaceFolder}", //工作目录 "environment": [], "externalConsole": true, //是否显示命令行,是为true,否为false。 "MIMode": "gdb", "miDebuggerPath": "E:\\mingw32\\bin\\gdb.exe", //gdb的位置 "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "ege" } ] } |
- tasks.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | { "version": "2.0.0", "tasks": [ { "type": "shell", "label": "ege", "command": "E:\\mingw32\\bin\\g++.exe", //g++的位置 "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe", "-lgraphics", //64位为"-lgraphics64", "-luuid", "-lmsimg32", "-lgdi32", "-limm32", "-lole32", "-loleaut32", "-lwinmm", "-lgdiplus", ], "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] } |
- settings.json
32位
1 2 3 4 5 | { "code-runner.executorMap": { "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -lgraphics -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lgdiplus && $dir$fileNameWithoutExt" } } |
64位
1 2 3 4 5 | { "code-runner.executorMap": { "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -lgraphics64 -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lgdiplus && $dir$fileNameWithoutExt" } } |
至此你就可以用VScode来编写ege库了,可以编译后运行,也可以调试了。