使用cl编译脚本:

cl -nologo -MD -GR -EHsc -std:c++17 main.cpp -I "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include" -I "D:\Windows Kits\10\Include\10.0.19041.0\ucrt" -I $env:ROOTSYS\include /link -LIBPATH:"D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\lib\x64" -LIBPATH:"D:\Windows Kits\10\Lib\10.0.19041.0\um\x64" -LIBPATH:"D:\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64" -LIBPATH:$env:ROOTSYS\lib libCore.lib libGpad.lib libHist.lib
main.exe

在powershell ISE中运行会有错误信息:

 

 原因是ISE中新启动一个console进行执行,没有err捕捉,用2> $NULL重置错误就好。

或者直接在powershell中而不是powershell ISE中运行。