Andy Leo Andy Leo - 2 years ago 155
C++ Question

Cannot run C++ code on the newly installed Visual Studio Code

I have done the following to try to set up development environment for C++ on macOS but in vain.

  1. I downloaded Visual Studio Code from Microsoft website and correctly installed.

  2. I installed ms-vscode.cpptools and mitaki28.vscode-clang.

  3. I installed gdb.

The following is the warning I got:

ld: warning: ignoring file /Users/andy/Documents/VS Code C++/Hello World/.vscode/tasks.json, file was built for unsupported file format ( 0x7B 0x0A 0x20 0x20 0x20 0x20 0x22 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x22 0x3A ) which is not the architecture being linked (x86_64): /Users/andy/Documents/VS Code C++/Hello World/.vscode/tasks.json

Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

EDIT 1: My platform is macOS.

EDIT 2: My problem occurred when I was trying to build the simplest Hello World project so that the problem cannot be my C++ code. But I am almost a novice so that I have no idea what the .json things are.

EDIT 3: I think the problem may lie in launch.json file, so this is my file:

"version": "0.2.0",
"configurations": [
"name": "C++ Launch (GDB)",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${file}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "g++",
"miDebuggerPath": "/usr/local/bin/gdb"


Answer Source

It seems that you just don't have a {somefile}.cpp file in your project (or the file is not being compiled) containing

int main() {
    return 0;


int main(int argc, char ** argv) {
    return 0;


You can safely ignore tasks.json warning - it's being mistakenly passed to linker input and the linker just ignores the file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download