调用Visual Studio的cl.exe编译C/C++程序
前言
由于每次打开visual studio都得费时间,想在Notepad++上写完直接编译运行,于是就打算调用VS的cl.exe编译器,就有了这篇文章
1.查看VS的路径
我安装VS时自己选择了安装路径,所以我的路径如下
D:\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe
这个是主程序的路径,而我们需要的是cl.exe的路径,所以应该是下面这个
D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe
我自己系统是64位的,所以是选择x64的cl.exe
2.添加环境变量
·· 在Path变量中(推荐设置用户的),添加cl.exe的路径(不带主程序)
D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\

·· 新建一个名为INCLUDE 的变量,填写以下内容
D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared;C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\winrt;

·· 新建一个名为LIB 的变量,填写以下内容
D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64;

部分路径可能不一样,自行修改
3.查看设置是否生效
用powershell或者cmd输入cl 看看

4.配置Notepad++
·· 安装NppExec插件
·· 插件 --> NppExec --> Execute NppExec Script… 
·· 输入以下命令,点击Save保存,名字自定义
cmd /c "pushd $(CURRENT_DIRECTORY) && CLS && cl /EHsc $(FULL_CURRENT_PATH)"
·· 插件 --> NppExec --> Advanved Options
在Associated script中选择刚刚保存的脚本,点击Add/Modify依次添加到Menu items中,期间注意修改Item name。在Menu items中勾选Place to the Macros submenu 
·· 添加快捷键
找到我们需要的CompilerC++ 

·· 重启Notepad++,测试脚本 
enjoy it~
|