0

I am trying to set up C++ on my apple silicon laptop and am running into some trouble. I am using VSCode and downloaded the C/C++ extension as well as code runner--I am now trying to simply print "hello world" but am running into trouble as I keep getting this error

[Running] cd "/Users/samdisorbo/Documents/code/C++/" && g++ learning.cpp -o learning && "/Users/samdisorbo/Documents/code/C++/"learning
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.075 seconds

I don't think it has anything to do with my code, so it must be an installation error right? I checked and clang and clang++ are both on my laptop...

here is my code

# include <iostream>

using namespace std;

int main(){

    printf("Hello World");
    return 0;
}

main();
  • 1
    Looks like you don't have a `main()` function in your cpp file. Can we get a [mre] of your code? – NathanOliver Jul 20 '21 at 20:28
  • 1
    ***I don't think it has anything to do with my code*** I would say it most likely has to do with your code. That is assuming that you have 1 single cpp file named `learning.cpp` the build commands look correct. The linker says it can't find the main() function defined in your compiled object file. Does your code have an `int main()` function in the global namespace? – drescherjm Jul 20 '21 at 20:38
  • I will add my code now – Samuel DiSorbo Jul 20 '21 at 22:18
  • `main();` is a bug. Should have caused an error. – drescherjm Jul 20 '21 at 22:35
  • `printf("Hello World");` is missing an include. – drescherjm Jul 20 '21 at 22:35
  • `# include ` There should not be a space between # and include. – drescherjm Jul 20 '21 at 22:35
  • with all the fixes I still get the same error – Samuel DiSorbo Jul 21 '21 at 14:19
  • I don't think you are compiling the file you think you are compiling. Your compiler should have given you different errors. Either the compiler is looking in a different folder than the file you have in VSCode or it's not saved at all. This is something you need to investigate with your OS file browser and possibly print the contents of the file from the shell. – drescherjm Jul 21 '21 at 14:21
  • I'm new to cpp and am just trying to start--what is a compiler haha – Samuel DiSorbo Jul 21 '21 at 14:28

0 Answers0