如何修复 visual-studio-code c++ 链接器命令失败错误

问题描述 投票:0回答:2

我用的是m1 air mac。 我在“0x09”文件夹中制作了 1012.cpp 文件。但我将“cpp”误输入为“Cpp”。我用vscode编译的时候出问题了

此处错误信息:

cd "/Users/7bella/Desktop/sourcecode/vscode_c/barkingDog/0x09/"
 && clang++ -std=c++17 1012.Cpp -o 1012 && "/Users/7bella/Desktop/sourcecode/vscode_c/barkin
gDog/0x09/"1012
ld: warning: ignoring file 1012.Cpp, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x23 0x69 0x6E 0x63 0x6C 0x75 0x64 0x65 0x20 0x3C 0x62 0x69 0x74 0x73 0x2F 0x73 )
Undefined symbols for architecture arm64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我将文件名更改为 1012.cpp,但仍然出现同样的错误。 错误消息说,文件名是 1012.Cpp 即使我将文件名更改为 1012.cpp

如果我将文件名更改为 ex) 1012_1.cpp 或将文件夹名称更改为 ex) 0x0A,则不会发生错误。 如何在保留文件名 1012.cpp 的同时解决此问题 请帮助我

如果我将文件名更改为 1012_1.cpp,它可以正常工作。 enter image description here

这是我的 task.json 文件:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ 활성 파일 빌드",
            "command": "/usr/bin/clang++",
            "args": [
                "-std=c++17",
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "컴파일러: /usr/bin/clang++"
        }
    ]
}
c++ compilation apple-m1
2个回答
1
投票

问题可能是文件扩展名没有正确更新。

试试这个命令:

mv 1012.Cpp 1012.cpp


0
投票

如果您共享 task.json 会很有用,无论如何,请查看该文件并检查您的命令选项是否与此类似:

"command": "/usr/bin/clang++"
这里有一个示例 task.json 文件:

  "tasks": [
{
    "type": "shell",
    "label": "clang++ build active file",
    "command": "/usr/bin/clang++",
    "args": [
        "-g",
        "${fileDirname}/*.cpp",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
    ],
© www.soinside.com 2019 - 2024. All rights reserved.