1. 程式人生 > >MAC環境下 VS Code中C語言標頭檔案匯入錯誤

MAC環境下 VS Code中C語言標頭檔案匯入錯誤

今天重新拾起了C語言,下載了vs code和CLion, 然後發現vs code寫好程式碼之後標頭檔案下方出現波浪線表示錯誤,百思不得其解。

然後看網上解答,找到了答案,好像是因為需要路徑設定

#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/Users/…/Desktop/ctest/main.c) will be provided by the Tag Parser.

解決方法是

在命令列裡面輸入gcc -v -E -x c++ -在結果裡面找到標頭檔案目錄,

#include <…> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks (framework directory)
End of search list.

將這些路徑值,全部copy到c_cpp_properties.json檔案中的includePath欄位下,警告消失

新的問題出現

在命令後執行gcc -v -E -x c++ - 出現一下錯誤警告
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

解決方法:

開啟終端輸入

xcode-select --install

回車後,系統彈出下載xcode,點選確認,下載完成後即可。(實際上不是下載xcode,可能下載xcode有關外掛,下載時長約1分鐘)

出現這個錯誤原因猜想可能是因為之前安裝過xcode解除安裝後出現的。

然後就順利解決了。

c_cpp_properties.json

c_cpp_properties.json

注意路徑之間要用逗號分開,並且加上引號哦~