Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
    }
]

}

like image 927
Andy Leo Avatar asked Feb 05 '26 17:02

Andy Leo


1 Answers

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;
}

or

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

function.

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

like image 175
Anton Malyshev Avatar answered Feb 08 '26 14:02

Anton Malyshev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!