r/cpp_questions • • 1d ago

OPEN Unable to fix C++ output

Undefined symbols for architecture arm64:
  "_main", referenced from:
      <initial-undefines>
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Hi. I've started learning C++ for Arduino and while practicing, I ran my code and the output is saying its a Clang++ error. I downloaded clang as it was recommended by a tutor on youtube,and it works for mark. Even basic print code wont work. Anyway to solve this?

2 Upvotes

8 comments sorted by

14

u/TheRealSmolt 1d ago

You don't have a main function, or your compiler can't find it. We need more info to help; things like code snippets, file structure, etc.

9

u/sharth 1d ago

Hi. You'll need to provide more information to have people help you.

Here's what we're looking for:

  1. Source code that you are compiling. Preferably, reduced down to the least interesting and least number of lines of code that still reproduces your problem.
  2. The commands that you ran to create the issue. clang++ -O3 foo.cc perhaps.
  3. The operating system you are running, and maybe information about the compiler that you are using. Or IDE if you are using one.
  4. The output that you find concerning, and what you actually wanted to see.

Here, you've only provided #4. The other three pieces of information are really vital to actually helping you though.

7

u/jedwardsol 1d ago

Are you saving your file after editing it?

4

u/TomDuhamel 1d ago

What about providing the command that caused that error?

But in itself, the error is pretty clear: What you compiled did not contain a main function.

2

u/Discordbothost 1d ago

Check whether you're building an Arduino sketch or a desktop program. If it's a sketch, use Arduino IDE with your board selected; the Arduino core supplies the entry point. A plain clang++ command leaves out that core, so adding main isn't the right fix for an Arduino sketch.

2

u/RealisticDuck1957 23h ago

Given the limited facts presented this seems the likely problem. An arduino sketch has different launch code and entry points from what the usual desktop C/C++ uses.

Now if you're writing code for arduino but want to test on desktop, a main() stub could call the arduino init() and loop. Provided of course that other arduino API calls are also provided for.

1

u/turtlesdontcry 1d ago

Definitelt missing main function.  Never seen this for anything else.  If it is something else I actually wanna know what else it could be.  Might learn something new.

1

u/PijanyRuski 1d ago

What Arduino are you using?