未找到架构 arm64 的符号 - VScode 上出现错误

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

我在 M1 Mac 上运行 VScode。 每当我尝试运行我的代码时,我总是收到此错误:

Undefined symbols for architecture arm64:
  "Array::Array(int)", referenced from:
      _main in Main-528956.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

对于 C++ 类来说,这是一个非常简单的项目,但这个错误超出了我的范围。 这是我必须使用的三个类:

数组.h:

#ifndef _ARRAY_H_
#define _ARRAY_H_

    class Array
    {
    public:
        Array();
        Array(int);
    private:
        int size;
        int *arr;
    };
    #endif

数组.cpp:

#include <iostream>
#include "Array.h"

using namespace std;

Array::Array()
{
    size = 0;
    arr = nullptr;
}

Array::Array(int s)
{
    size = s;
    arr = new int[size];
    for (int i = 0; i < size; i++)
    {
        arr[i] = i;
    }
    cout << "overloaded constructor works" << endl;
    delete[] arr;
}

主.cpp:

#include <iostream>
#include "Array.h"

using namespace std;

int main()
{

    Array arr1(5), arr2(10);
    return 0;
}

如果我需要添加任何其他信息,请告诉我。

c++ visual-studio error-handling runtime-error
1个回答
0
投票

/usr/bin/clang
更改为
/usr/bin/clang++

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
© www.soinside.com 2019 - 2024. All rights reserved.