我做了以下尝试在 macOS 上为 C++ 设置开发环境,但没有成功。
我从 Microsoft 网站下载并正确安装了 Visual Studio Code。
我安装了 ms-vscode.cpptools 和 mitaki28.vscode-clang。
我安装了 gdb。
以下是我收到的警告:
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)
编辑 1:我的平台是 macOS。
编辑 2:我在尝试构建最简单的 Hello World 项目时出现了问题,因此问题不可能出在我的 C++ 代码上。但我几乎是一个新手,所以我不知道 .json 是什么东西。
编辑 3:我认为问题可能出在 launch.json 文件中,所以这是我的文件:
{
"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"
}
]
最佳答案
看来您的项目中没有包含
的{somefile}.cpp
文件(或者该文件未被编译)
int main() {
...
return 0;
}
或
int main(int argc, char ** argv) {
...
return 0;
}
函数。
您可以安全地忽略 tasks.json 警告 - 它被错误地传递给链接器输入,链接器只是忽略该文件。
关于c++ - 无法在新安装的 Visual Studio Code 上运行 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45709338/