Tag Archives: Mac Vscode C++ Customize Header File Error

Mac Vscode C++ Customize Header File Error: linker command failed

Project scenario:

Customized a swap header file and failed to compile


Cause analysis:

Tip: C_cpp_properties.json and tasks.json only the current file is compiled by default. If only main.cpp is selected, it will only compile this one file.

Solution:

Tip: modify C_cpp_properties.json and tasks.json configuration file, which compiles the source files in the specified directory.

c_cpp_properties.json Modify:

“includePath”: [
“${workspaceFolder}/**”
"configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang++",
            "cStandard": "c11",
            "cppStandard": "c++98",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}


Modify tasks.json

“-g”,
“${fileDirname}/*.cpp”
{
	"version": "2.0.0",
	"tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: clang++ files",
      "command": "/usr/bin/clang++",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${fileDirname}/*.cpp",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Compiler: /usr/bin/clang++"
    }
  ]
}

After saving, return to the project folder, click Shift + Command + B in the blank space to compile, and then execute the compiled program ./main in terminal.