Should be straightforward, but when I compile the C++ Hello World code returns a bunch of undefined symbol errors.
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
Heres how I compile: Open terminal, cd to the directory, gcc hello.cpp
Then I get the errors. Any thoughts? I feel like I may have broken somehting... or I am just missing something really obvious. Any help is greatly appreciated!
Heres the errors:
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in ccfUAf5i.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccfUAf5i.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccfUAf5i.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccfUAf5i.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
You need to use g++
to compile and link C++ code:
g++ hello.cpp -o hello
Or to be fully Stack Overflow compliant:
g++ -W -Wall -Werror -pedantic -o hello hello.cpp
Use g++ instead of gcc. But anyways your gcc installation seems to be broken. Also are you trying to compile 64bit exec on a 32 bit machine/os?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With