0

I recently downloaded vs code in my m1 mac after downloading the g++ compiler in the terminal and then I downloaded the extensions C/C++ IntelliSence and Code Runner. After doing that I wrote a simple Hello World program but it threw me an error.

Code:

#include<iostream>
using namespace std;
void main()
{
   cout<<"Hello World";
}

Output:

[Running] cd "/Users/mohammedalif/HelloWorld/" && g++ main.cpp -o main &&
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.22 seconds

This is the screenshot of the output I got along with the code

enter image description here

This is what i am getting instead of a simple Hello World output.

What should I do to fix this???

AEM
  • 1,354
  • 8
  • 20
  • 30
  • `void main()` is not a valid signature for main. Related: [https://stackoverflow.com/questions/4207134/what-is-the-proper-declaration-of-main-in-c](https://stackoverflow.com/questions/4207134/what-is-the-proper-declaration-of-main-in-c) also this online g++ shows an error about that: [https://ideone.com/comNhN](https://ideone.com/comNhN) – drescherjm Apr 11 '21 at 21:00

2 Answers2

1

You need to use int main() instead of void main().

Also before closing the main function, write return 0; which basically indicates that we are not returning any value to this function.

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
1

First of all correct in C/C++ is:

int main()

or

int main(int args,char * argv[])

Check this video: https://www.youtube.com/watch?v=rS7GUCBulww&t=599s In the video girl show, how install and configurate VS Code in Apple M1: