在win10的vscode中编译调试std::thread
1.下载MinGW:x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z:posix版本支持std::thread,所以请选择posix版本。
或者从百度网盘下载:https://pan.baidu.com/s/1rRCqNHaVqQQk0TP-dDZvKA 提取码:30nc
2.解压7z,将mingw64放在C盘根目录下
3.设置launch.json的“environment”,如下所示:
"environment": [ { "name":"PATH", "value": "%PATH%;C:\\mingw64\\bin;C:\\mingw64\\opt\\bin;C:\\mingw64\\libexec\\gcc\\x86_64-w64-mingw32\\8.1.0;C:\\mingw64\\x86_64-w64-mingw32\\bin" } ],
将所有可能的bin都放在里面。我这边将所有库都放进去之后,gdb就可以launch啦,之后可以顺利调试std::thread代码
4.在task.json的“args”,添加-pthread,如下所示:
"args": [ "-g", // 编译参数设置-g表示可以使用gdb调试// "-D_GLIBCXX_USE_NANOSLEEP", // "-fno-elide-constructors", "-pthread", "${workspaceFolder}/*.cpp", "${workspaceFolder}/universal/*.cpp" , "${workspaceFolder}/multithread/*.cpp", "-o", "train"],