【发布时间】:2021-09-21 06:25:00
【问题描述】:
我只是在 CPP 中的 Mac m1 上运行一个基本程序。这是代码:
#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);
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);
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]);}
每次运行此代码时都会出现此错误:
[Running] cd "/Users/siddhpurohit/Documents/vs code/DSU/" && gcc Exp1.c -o Exp1 && "/Users/siddhpurohit/Documents/vs code/DSU/"Exp1
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)
[Done] exited with code=1 in 0.227 seconds
如果您知道如何纠正此错误,请告诉我。我是新手,对编码了解不多……但我希望学习。
【问题讨论】:
-
int main({??这真的是你的代码的样子吗?应该是int main(int argc, char **argv) { ...}或int main(void) { .. } -
AFAIK 在 gcc 中还没有对 M1 arm 构建的官方支持。这里有工作正在进行中:github.com/iains/gcc-darwin-arm64。您也许可以使用 Rosetta 运行 x86 二进制文件,但我不是这方面的专家,因此无法提供有关这些方面的任何进一步信息。
-
请缩进你的代码
标签: arrays c visual-studio-code