ld: symbol(s) not found for architecture arm64

Hi,all

I'm writing a simple c program on my m1 MacBook with vscode ,but when I complied the project, error occurs:

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)

I installed Xcode and used vscose

and my program is :


#include <cstdio>
int main()
{
    char name[100];printf("please input your name:");
    scanf("%s",name);
    printf("hello,%s",name);
}

Replies

I recommend that you start by getting this running from the command line. That’ll tell you whether the problem is with your command-line tools setup or in how you’re invoking those tools.

Consider this:

% cat test.cpp 
#include <cstdio>
int main()
{
    char name[100];printf("please input your name:");
    scanf("%s",name);
    printf("hello,%s",name);
}
% clang test.cpp
% ./a.out
please input your name:cruel world
hello,cruel
% file a.out
a.out: Mach-O 64-bit executable x86_64

Note If you’re running on Apple silicon, the last command should say arm64 not x86_64.

Does that work for you?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Hello,

    I am facing a similar error with clang, I am also using the M1 macbook inline-code ld: symbol(s) not found for architecture arm64

    clang: error: linker command failed with exit code 1 (use -v to see invocation) inline-code my code is

    `#include

    #include

    using namespace std;

    int main() {

      cout << "Hello World!!!" << endl;

      int v = 10;

      return 0;

    };`

    I tried what was suggested by eskimo. His code runs fine for me and I get

    'file a.out a.out: Mach-O 64-bit executable arm64'

    but I am unable to run the simple Hello World program. I am a beginner at C++ Could someone please help?

    Thanks in advance

Add a Comment

Hello,

I am facing a similar error with clang, I am also using the M1 macbook


ld: symbol(s) not found for architecture arm64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

my code is

#include <cstdio>

#include <iostream>

using namespace std;



int main() {

  cout << "Hello World!!!" << endl;

  int v = 10;

  return 0;

};

I tried what was suggested by eskimo. His code runs fine for me and I get


file a.out
a.out: Mach-O 64-bit executable arm64

but I am unable to run the simple Hello World program. I am a beginner at C++ Could someone please help?

Thanks in advance

  • For C++, you will need to use "clang++"

Add a Comment