0

I'm doing a basic Hello World script, and anytime I try to compile it from the command line (example gcc -o hello.o hello.cpp) I get a massive cascade of errors before being informed that the linker exited with an error. However, when I build the file via the Eclipse C++ IDE, it works fine. I'm on MacOS 11.3.1. Checking the version of the compiler with gcc -v gives me

Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I've verified that if I simply put a main function that returns a value it will compile, so the issue is somewhere with the std::cout << "Hello world"; line. I have some experience with other languages, but this is my first attempt at anything with C++.

  • 2
    Try `g++` instead of `gcc`. Beyond that, show the actual errors. – paddy Aug 09 '21 at 03:29
  • 1
    *"I get a massive cascade of errors"* -- the first error is almost always the most important. Feel free to focus on that one (and include the message in your question) and ignore the rest for now. – JaMiT Aug 09 '21 at 03:39
  • You might want to look at the command that Eclipse uses to compile your program. (It should be available somewhere, albeit maybe a bit hidden.) That might tell you which command-line options you need to provide. – JaMiT Aug 09 '21 at 03:40
  • 2
    I also would **not** name your executable with a `.o` extension. – sweenish Aug 09 '21 at 04:22

0 Answers0