You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac M1下VS Code Insider运行C++报arm64架构未定义符号错误如何解决

错误本质说明

你遇到的undefined symbol for architecture arm64报错并非M1芯片架构不兼容导致,核心原因是你的C代码存在多处语法错误,导致编译器无法正确识别程序入口main函数,链接阶段找不到入口符号才触发报错。

代码存在的具体语法错误
  • main函数定义语法错误:原代码写为int main({,缺少参数列表的闭合右括号,正确写法为int main() {
  • 变量名大小写错误:读取数组元素的代码中使用了大写的I,但你定义的变量是小写的i,C语言大小写敏感,会被识别为未定义变量
  • main函数被提前意外关闭:读取单个数组元素的scanf语句后多写了一个},直接把main函数提前结束,后续代码都不属于main函数范畴,编译器判定你没有定义合法的程序入口
  • 缺少数组元素读取循环:原代码只写了一次读取数组元素的逻辑,没有循环读取你输入的n个元素
  • 缺少数组越界防护:你定义的数组容量只有10,插入元素后总数不能超过10,插入位置也需要合法性校验
修正后可正常运行的完整代码
#include <stdio.h>
int main() {
    int i, n, num, pos, arr[10];
    printf("\n Enter the number of elements in the array: ");
    scanf("%d", &n);
    // 循环读取n个初始数组元素
    for(i = 0; i < n; i++) {
        printf("\n arr[%d] = ", i);
        scanf("%d", &arr[i]);
    }
    printf("\n Enter the number to be inserted : ");
    scanf("%d", &num);
    printf("\n Enter the position at which the number has to be added : ");
    scanf("%d", &pos);
    // 增加合法性校验,避免数组越界
    if(pos < 0 || pos > n || n >= 10) {
        printf("\n Invalid position or array is full, insert failed");
        return 1;
    }
    for(i = n-1; i >= pos; i--) {
        arr[i+1] = arr[i];
    }
    arr[pos] = num;
    n = n + 1;
    printf("\n The array after insertion of %d is : ", num);
    for(i = 0; i < n; i++) {
        printf("\n arr[%d] = %d", i, arr[i]);
    }
    return 0;
}
运行验证

将代码修改保存后,再用你原来的编译命令运行即可,M1芯片自带的clang/gcc完全兼容arm64架构,不需要额外调整编译参数。

内容的提问来源于stack exchange,提问作者Siddh Purohit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 09:39:05