在Visual Studio Code中編譯C/C代碼時,您可能會在#include 下遇到一個綠色行,以指示“添加路徑”。 This guide will delve into the solution, exploring how to specify include paths in the Visual Studio Code configurations.
Adding Include Paths to Configurations
Locate the "c_cpp_properties.json" File:
Navigate to your project's directory and look for the .vscode folder.在此文件夾中,您會找到“ C_CPP_PROPERTIES.JSON”文件。
打開“ c_cpp_properties.json”文件,並查找“配置” array array。在此數組中,您可以指定不同配置的路徑,例如“ MAC”,如下所示:- “ configurations”:[
{
“名稱”:“ Mac”,
“ includepath”:[“/usr/include”]
}
] 以添加附加include路徑,只需將它們包含在“ IncludePath”數組作為字符串中即可。用逗號將每個路徑分開。例如,要添加“ my_include”目錄,更新的配置將是: [griendionurations':[
{
“名稱”:“ Mac”,
“ includepath”:[/usr/include“,”/my_include”]
}
]
利用“ CompilerPath”選項- 現在在Visual Studio Code中的C擴展名現在提供一個可選的“ CompilerPath”字段中的“ C_CPP_PROPERTIES”。設置時,擴展程序將查詢指定的編譯器以確定係統包括路徑,默認的IntelliSense定義。 用於編譯和執行C或C代碼,請考慮使用Tasks.json文件,該文件提供了一種方便的方法來定義自定義構建並在Visual Studio代碼中運行命令。