【发布时间】:2021-09-30 05:20:23
【问题描述】:
我在 MacOS 上运行 VS Code,我正在使用 clang 编译一个简单的“Hello World!” C++ 中的程序。但是,当我尝试运行我的程序时,VS Code 给了我以下错误消息:Undefined symbols for architecture arm64: 后跟几十个对std 库的引用。在终端的底部,它说:
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Build finished with error(s).
The terminal process terminated with exit code: -1.
(a) 这是什么意思? (b) 我该如何解决?
HelloWorld.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/clang",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "clang - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/HelloWorld.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang build active file"
}
]
}
谢谢!
【问题讨论】:
-
您的活动文件构建失败。查看您的集成终端以获取实际详细信息。
-
你在编译的时候关注过你想要构建的cpp吗?
-
显示错误,会有所帮助
-
@LouisGo @Lala5th 终端显示
Undefined symbols for architecture arm64:,然后提供大量来自std命名空间的引用。我认为这与我如何为 VS Code 提供iostream.h的包含路径有关? -
Edit 您的问题并提供您的 helloworld.cpp 和错误消息。您不需要包含所有 std 未定义的参考错误,但其他人有有意义的细节。它应该会有所帮助。
标签: c++ visual-studio-code clang std