VSC not working on MacOS

Joined
Feb 4, 2020
Messages
1
Reaction score
0
Points
1
When trying to compile a simple program I am getting this error using Visual Studio Code on my MacBook Pro. Trying to avoid using Pico as my editor because it sucks. Please help!

eph525@Anthonys-MBP MAE 2360 % g++ Test.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-W
deprecated]
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
eph525@Anthonys-MBP MAE 2360 %

My code is this:

#include<stdio.h>

int main()
{
printf("Hello world");
return 0;
}
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,745
Reaction score
2,071
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
A couple of things. You are writing a C program and should be using 'gcc' to compile it. 'g++' is used for C++ development.

My version of your Hello World application is:
Code:
#include <stdio.h>


int main(void) {
    printf("Hello World\n");
    return 0;
}

I compile with
Code:
gcc -o hello hello.c

Not providing the '-o' option means you get a.out which can be confusing. :)

Now, I did use 'g++' to compile my code and beyond that (correct) warning, it did compile and run.

The fact that you are getting the other errors means that you don't have the command line build tools install, ensure you do so with
Code:
xcode-select --install

You should then have the C Library necessary to run your program.

You should also likely install Xcode which is an awesome IDE for for your development needs. You can write programs in C, C++ and Objective-C for macOS, iOS, WatchOS and so on in there.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top