I’ve written a simple c++ program, test.cpp:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
cout << s << endl;
return 0;
}
Why does runnning gcc test.cpp -o mytest give me these errors, and more?
Undefined symbols for architecture x86_64:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
_main in cc8rGYVq.o
"std::cin", referenced from:
_main in cc8rGYVq.o
Don’t use the executable named
gccto compile and link C++ programs; you must useg++. Not only does it select the appropriate compiler options, it also links with the right libraries for your language (which is the problem you’re having here.)