天天看點

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解除安裝後出現的。

然後就順利解決了。

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

c_cpp_properties.json

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

繼續閱讀