-
在vscode使用中如果想使用自定義的函數庫或者第三方庫需要對tasks和c_cpp_properties.json中的路徑進行配置。
-
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32", // 配置名稱可隨意更改
"includePath": [ //運行項目包含.h頭文件的目錄,在此處添加外部頭文件路徑
"${workspaceFolder}/**",
"C:/test" //外部路徑
//此處會匹配工作文件下的所有文件
], //添加"compilerPath"后,系統include路徑可不寫明
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/MinGw/bin/g++.exe",//編譯器的路徑
"cStandard": "c17",//C標准的版本
"cppStandard": "c++17",//C++標准的版本
"intelliSenseMode": "${default}"
}
],
"version": 4
}
- tasks.json
使用 “-I” include 頭文件以及源文件路徑(若函數定義與聲明不在一起)。
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++build",
"command": "D:/MinGw/bin/g++.exe",
"args": [
"-g",
"${file}",
"-I",//引入外部頭文件
"F:\\C++\\headfile",
"F:\\C++\\headfile\\hello.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-std=c++17"
],
"options": {
"cwd": "D:/MinGw/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "編譯器: D:/MinGw/bin/g++.exe"
}
]
}
參數解讀:
gcc帶不同參數的含義:"-g"產生調試信息,"-c"編譯中間目標文件,"-I"指定鏈接庫,"-o"生成指定命名的可執行文件
總結&筆記:
相關代碼:
${workspaceFolder} :表示當前workspace文件夾路徑,也即/home/Coding/Test
${workspaceRootFolderName}:表示workspace的文件夾名,也即Test
${file}:文件自身的絕對路徑,也即/home/Coding/Test/.vscode/tasks.json
${relativeFile}:文件在workspace中的路徑,也即.vscode/tasks.json
${fileBasenameNoExtension}:當前文件的文件名,不帶后綴,也即tasks
${fileBasename}:當前文件的文件名,tasks.json
${fileDirname}:文件所在的文件夾路徑,也即/home/Coding/Test/.vscode
${fileExtname}:當前文件的后綴,也即.json
${lineNumber}:當前文件光標所在的行號
${env:PATH}:系統中的環境變量