ld: symbol(s) not found for architecture x86_64

Im writing a simple code on my MacBook, but when compiled I get an error message

[ 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) ]

Replies

Please list the steps in detail on what you did to create the code and compile it. The information you provided isn't enough for people to answer your question. Providing more details on what you did to create the code and compile it will give people here a chance to give you a helpful answer.

You tagged your question as Xcode, but your screenshot looks like Visual Studio Code. Did you create a project in Xcode or create a C++ file in Visual Studio Code?

Does you MacBook have an Intel processor or an Apple Silicon (M1 or M2 chip)? The linker error says it can't find a main function for the Intel architecture.

I installed vs code, and installed c/c++ extension and code runner. Then I installed clang into my terminal. I created a c++ file in visual studio code, then proceeded to write a basic code and run it. My MacBook has a 1.1 GHz Quad-Core Intel Core i5 Ventura 13.4.

In situations like this I recommend that you try to tease apart issues with your command-line tools from issues with your IDE. In this post I show how to build a trivial C++ program from the command line. Does that work for you? If so, your command-line tools are working just fine, and this is issue is specific to your third-party IDE.

Share and Enjoy

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