【Win10 环境vscode配置boost】
这里写自定义目录标题Boost exe版本windows环境安装vscode配置安装测试总结Boost exe版本windows环境安装这里不介绍boost源码安装,请自行网络搜索。本文要介绍的是window下单c++文件(cpp),调用boost库的执行配置。不涉及多文件。安装文件下载地址:+下载版本boost_1_87_0-msvc-14.1-32.exe 。最新版本请访问这里下载本人安装路径
·
Boost exe版本windows环境安装
这里不介绍boost源码安装,请自行网络搜索。本文要介绍的是window下单c++文件(cpp),调用boost库的执行配置。不涉及多文件。vscode需要配置好C++开发环境,请自行网络搜索。
安装文件下载地址:
+下载版本boost_1_87_0-msvc-14.1-32.exe 。最新版本请访问这里下载
本人安装路径:D:\software\boost_1_87_0
- 配置环境变量
配置boost头文件和库文件环境变量: BOOST_INCLUDEDIR 和 BOOST_LIBRARYDIR
path 中添加 D:\soft\boost\172\lib64-msvc-14.2
vscode配置
vscode安装和C++开发环境配置这里不表述,请网络自行搜索。运行C++文件需要。vscode请安装code runner插件。
测试目录创建.vscode目录,目录中创建相关json配置文件。直接上相关配置文件。
- task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "D:\\software\\mingw64-14.2\\bin\\g++.exe",
"args": [
"-I",
"D:\\software\\boost_1_87_0",
"-fdiagnostics-color=always",
"-g",
"${file}",
"-g", // 生成调试相关信息
"-Wall", // 生成额外告警信息
"-static-libgcc", // 静态libgcc,一般都会加上
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-std=c++17"
],
"options": {
"cwd": "D:/software/mingw64-14.2/bin"
},
// "problemMatcher": ["$gcc"], // 此选项可以捕捉编译时终端里的报错信息;但因为有Lint,再开...
"group": {
"kind": "build",
"isDefault": true // 不为true时 ctrl shift B时就需要手工选择
},
"detail": "D:\\software\\mingw-64\\mingw64-8.1\\bin\\g++.exe",
"presentation": {
"echo": true,
"reveal": "always", // 执行任务时是否跳转到终端面板,可以为always,silent,never
"focus": false, // 设为true后可以使执行task时焦点聚集在终端,但对编译C/C++来讲...
"panel": "shared" // 不同的文件的编译信息共享一个终端面板
},
}
]
}
- lanch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "调试C++程序",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 指定要调试的程序路径
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb", // 使用gdb作为调试器。
"miDebuggerPath": "gdb", // gdb的路径。如果未添加到PATH环境变量,需要填写完整路径。
"setupCommands": [
{
"description": "启用调试打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
- c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:\\software\\boost_1_87_0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\software\\mingw64-14.2\\bin\\g++.exe",
"cStandard": "c17", // 指定C的标准版本
"cppStandard": "c++17", // 指定C++的标准版本
"intelliSenseMode": "windows-gcc-x64" // 指定IntelliSense的模式
}
],
"version": 4
}
- settings.json
{
"cmake.configureOnOpen": true,
"files.associations": {
"*.ipp": "cpp",
"valarray": "cpp"
},
"code-runner.executorMap":{
"cpp": "cd $dir && g++ $fileName -I \"D:\\software\\boost_1_87_0\" -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
}
}
说明:如果没有code-runner.executorMap配置,vscode code runner执行cpp时会提示如下类似找不到boost头文件的错误:
[Running] cd "e:\codes\C++\myC++\test\" && g++ main.cpp -o main && "e:\codes\C++\myC++\test\"main
main.cpp:1:10: fatal error: boost/algorithm/string.hpp: No such file or directory
1 | #include <boost/algorithm/string.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
[Done] exited with code=1 in 7.869 seconds
安装测试
测试代码:
#include <boost/algorithm/string.hpp>
#include <iostream>
using namespace std;
using namespace boost;
int main()
{
cout << "------------测试boost库安装是否正确------------" << endl;
std::string s = "ismileli";
// 把字符串小写转换为大写
std::cout << boost::algorithm::to_upper_copy(s) << std::endl;
std::cout << "Hello World!\n";
}
执行结果:
[Running] cd "e:\codes\C++\myC++\test\" && g++ main.cpp -I "D:\software\boost_1_87_0" -o main && "e:\codes\C++\myC++\test\"main
------------测试boost库安装是否正确------------
ISMILELI
Hello World!
[Done] exited with code=0 in 3.564 seconds
总结
- 本文配置适用于单c/cpp文件执行,不适合工程级别配置。仅供学习使用。boost文件可以自由跳转。
- 关于setttings.json中的配置,我认为cpp文件的编译指令应有更好的实现方式,当前实现放在这个文件不是最佳。后续会更新。欢迎知道的网友留言。
更多推荐
所有评论(0)