1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[macOS] VSCodeでiostreamなどのC++標準ライブラリが見つからないエラーの対応(llvm/clangの例)

Posted at

VSCodeのC/C++拡張機能のIntelisenseのInclude Path設定

環境など

  • macOS
  • VSCode
    • 拡張機能: C/C++ (Extension Pack)
  • llvm/clang

設定手順

  • C/C++設定ファイルを開く
    • Cmd+Shift+P、
  • 必要な設定を調べる
    • clang++ -v -E -x c++ -
    • Ctrl+Cで終了する。
    • 出力されたコマンド引数から必要な引数を抜き出してincludePathに追加する。
saitama@MacBook-Pro bug-finder % clang++ -v -E -x c++ -
Homebrew clang version 11.1.0
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm@11/bin
 (in-process)
 "/usr/local/Cellar/llvm@11/11.1.0_4/bin/clang-11" -cc1 -triple x86_64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-rounding-math -munwind-tables -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -debugger-tuning=lldb -target-linker-version 820.1 -v -resource-dir /usr/local/Cellar/llvm@11/11.1.0_4/lib/clang/11.1.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -stdlib=libc++ -internal-isystem /usr/local/opt/llvm@11/bin/../include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/local/include -internal-isystem /usr/local/Cellar/llvm@11/11.1.0_4/lib/clang/11.1.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include -fdeprecated-macro -fdebug-compilation-dir /Users/saitama/go/src/github.com/tractrix/bug-finder -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -o - -x c++ -
clang -cc1 version 11.1.0 based upon LLVM 11.1.0 default target x86_64-apple-darwin21.6.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/opt/llvm@11/bin/../include/c++/v1
 /usr/local/Cellar/llvm@11/11.1.0_4/lib/clang/11.1.0/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks (framework directory)
End of search list.
^C

上記の#include <...> search starts here:から下に表示されるパスで必要そうなものをincludePathに追加する。

(例では(framework directory)は追加していない。)

例:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/opt/llvm@11/bin/../include/c++/v1",
                "/usr/local/Cellar/llvm@11/11.1.0_4/lib/clang/11.1.0/include",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include",
            ],
            "defines": [
                "__cplusplus"
            ],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/local/opt/llvm@11/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++11",
            "intelliSenseMode": "macos-clang-x64",
            "compilerArgs": []
        }
    ],
    "version": 4
}

参考サイト

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?