@@ -48,13 +48,22 @@ cd vcpkg
4848.\vcpkg integrate install
4949```
5050
51+ 3 . 如果你使用的中文 Visual Studio,因为没有安装英文语言包,vcpkg 可能会无法正常工作。请打开 Visual Studio Installer 安装英文语言包(只需要安装英文语言包,不需要把 Visual Studio 切换为英文)
52+
53+ ![ 通过 Visual Studio Install 安装英文语言包] ( ./doc/pic/install_vs_eng_pkg.png )
54+
55+
5156#### (2) 使用 ** vcpkg** 安装 ** mirai-cpp**
5257
5358这一步稍微复杂,你需要执行(这里一定要在 ** Powershell** 里面执行):
5459
5560``` powershell
56- git clone https://github.com/cyanray/mirai-cpp-vcpkg-port.git tmp ; rm -Recurse -Force ports/mirai-cpp ; mv tmp/* ports/ ; rm -Recurse -Force tmp
57- ./vcpkg install mirai-cpp mirai-cpp:x64-windows
61+ git clone https://github.com/cyanray/mirai-cpp-vcpkg-port.git tmp ; mv tmp/* ports/ ; rm -Recurse -Force tmp
62+
63+ ./vcpkg install mirai-cpp
64+
65+ # 对于 x64 的项目,还需要执行:
66+ #./vcpkg mirai-cpp:x64-windows
5867```
5968
6069耐心等待,上面的指令会帮你安装 mirai-cpp 以及它的依赖项目。
@@ -71,14 +80,12 @@ int main()
7180{
7281 using namespace std;
7382 using namespace Cyan;
83+ system ("chcp 65001");
7484 MiraiBot bot("127.0.0.1",8080);
7585 while (true)
7686 {
7787 try
7888 {
79- // InitKeyVl0CEUzZ 改为你的 InitKey,
80- // 2110000000 改为你的 bot 的 QQ 号码
81- // 提示: mirai-cpp 中,数字后面加上 _qq 表示 qq 号码,数字后面加上 _gid 表示群号码。
8289 bot.Auth("InitKeyVl0CEUzZ", 2110000000_qq);
8390 break;
8491 }
@@ -87,21 +94,20 @@ int main()
8794 cout << ex.what() << endl;
8895 }
8996 }
90- cout << "成功登录 bot。" << endl;
91-
97+ cout << "Bot Working..." << endl;
9298
9399 bot.On<FriendMessage>(
94100 [&](FriendMessage m)
95101 {
96- // bot.SendFriendMessage (fm.Sender.QQ, fm.MessageChain);
102+ // bot.SendMessage (fm.Sender.QQ, fm.MessageChain);
97103 m.Reply(m.MessageChain);
98104 });
99105
100106 bot.On<GroupMessage>(
101107 [&](GroupMessage m)
102108 {
103- // bot.SendGroupMessage (gm.Sender.Group.GID, "为什么要 " + gm.MessageChain);
104- m.QuoteReply("为什么要 " + m.MessageChain);
109+ // bot.SendMessage (gm.Sender.Group.GID, "What is " + gm.MessageChain);
110+ m.QuoteReply("What is " + m.MessageChain);
105111 });
106112
107113 bot.EventLoop();
@@ -130,6 +136,9 @@ MSVC 并没有默认启动对 UTF-8 编码的支持。
130136
131137如果一切正常,给你的机器人发消息,他会回复同样的消息给你!
132138
139+ > 提示: 添加了编译参数 ** /utf-8** 后,** 你的项目** 的** 源文件的编码** 也必须是 ** UTF-8** 编码,不然会出现编译错误。中文操作系统下,Visual Studio 创建的源文件默认为 ** GB2312** 编码。所以你需要手动地修改** 你的项目** 的源文件为 ** UTF-8** 编码。
140+
141+
133142</details >
134143
135144
@@ -154,6 +163,11 @@ cd vcpkg
154163.\vcpkg integrate install
155164```
156165
166+ 3 . 如果你使用的中文 Visual Studio,因为没有安装英文语言包,vcpkg 可能会无法正常工作。请打开 Visual Studio Installer 安装英文语言包(只需要安装英文语言包,不需要把 Visual Studio 切换为英文)
167+
168+ ![ 通过 Visual Studio Install 安装英文语言包] ( ./doc/pic/install_vs_eng_pkg.png )
169+
170+
157171#### (2) 使用 ** vcpkg** 安装 ** mirai-cpp** 的依赖项目
158172
159173``` powershell
@@ -194,17 +208,94 @@ git clone https://github.com/cyanray/mirai-cpp.git
194208
195209在更新 mirai-cpp 之前,需要先删除已经安装的 mirai-cpp
196210
211+ Windows:
212+
197213``` powershell
198214./vcpkg remove mirai-cpp mirai-cpp:x64-windows
199215```
200216
217+ Linux:
218+
219+ ``` bash
220+ ./vcpkg remove mirai-cpp
221+ ```
222+
201223删除之后,重新安装即可:
202224
225+ Windows:
226+
203227``` powershell
204228git clone https://github.com/cyanray/mirai-cpp-vcpkg-port.git tmp ; rm -Recurse -Force ports/mirai-cpp ; mv tmp/* ports/ ; rm -Recurse -Force tmp
229+
205230./vcpkg install mirai-cpp mirai-cpp:x64-windows
206231```
207232
233+ Linux:
234+ ``` bash
235+ git clone https://github.com/cyanray/mirai-cpp-vcpkg-port.git tmp ; rm -rf ports/mirai-cpp ; mv tmp/* ports/ ; rm -rf tmp
236+ ./vcpkg install mirai-cpp
237+ ```
238+
239+ #### (2) 将程序轻松移植、部署到 Linux 上
240+
241+ <details >
242+
243+ (以下内容基于 “快速尝试2”,请先完成“快速尝试2”。)
244+
245+ 上面的内容介绍了如何在 Windows 上开发使用 mirai-cpp 的程序,下面来介绍如何将你的程序移植到 Linux 平台,以便将程序部署到 Linux 服务器上。
246+
247+ 为了易于讲解与操作,以下内容在 ** WSL** (** W** indows ** S** ubsystem for ** L** inux) 上进行。这里不对如何安装 WSL 进行说明,关于如何安装 WSL 还请自行查阅资料。
248+
249+ 1 . 在 WSL 上安装 vcpkg
250+
251+ 步骤与上文类似,但是略有不同:
252+
253+ ``` bash
254+ git clone https://github.com/Microsoft/vcpkg.git
255+ cd vcpkg
256+ ./bootstrap-vcpkg.sh
257+ ```
258+
259+ ![ 在 WSL 上安装 vcpkg] ( ./doc/pic/install_vcpkg_on_linux.png )
260+
261+ 耐心等待,其结果如图所示。
262+ 注意,如果执行 ls 发现没有生成 vcpkg 的可执行文件,请尝试重新执行上述的安装指令。(这似乎是个bug)
263+
264+ ![ 在 WSL 上安装 vcpkg2] ( ./doc/pic/install_vcpkg_on_linux2.png )
265+
266+ 2 . 使用 vcpkg 安装 mirai-cpp
267+
268+
269+ ``` bash
270+ git clone https://github.com/cyanray/mirai-cpp-vcpkg-port.git tmp ; mv tmp/* ports/ ; rm -rf tmp
271+
272+ ./vcpkg install mirai-cpp
273+ ```
274+
275+ ![ 在 WSL 上安装 mirai-cpp] ( ./doc/pic/install_mirai_cpp_on_linux.png )
276+
277+ 3 . 创建针对 WSL 的配置
278+
279+ 打开在 “快速尝试2” 中用到的项目。按照如图所示步骤,创建一个针对 WSL 平台的配置。因为我的 WSL 安装了 GCC 编译器,所以这里选择 ** WSL-GCC-Releas** 。
280+
281+ ![ 创建WSL-GCC平台配置1] ( ./doc/pic/vs_configure_linux_project.png )
282+
283+ 和 “快速尝试2” 一样的操作,配置 CMake Toolchain File。但是这次的路径要填写 WSL 上的路径。
284+
285+ ![ 创建WSL-GCC平台配置2] ( ./doc/pic/vs_configure_linux_project2.png )
286+
287+ Enjoy it;
288+
289+ </details >
290+
291+ ## 常见问题
292+
293+ ### 1. 使用 vcpkg 安装 mirai-cpp 时出错
294+
295+ 首先检查是不是网络错误导致下载文件失败。这种错误只要重新执行 ` ./vcpkg install mirai-cpp ` 。如果你有可以加速网络的代理服务器,可以添加 ** HTTP_PROXY** 和 ** HTTPS_PROXY** 环境变量,以加速 ** vcpkg** 的下载。
296+
297+ ![ 配置环境变量] ( ./doc/pic/env.png )
298+
208299## 代码风格
209300
210301本项目的代码使用的是我自己喜欢的代码风格,如果你有更好的建议(比如修改为 Google-Style),欢迎提出 issues 或 pull request。
0 commit comments