I'm learning programming with C++ at the university, so keep in mind that my skills are still limited. We're using Visual Studio so I installed Visual Studio Code on my MacBook, since there is no full Visual Studio for OS X. When I try to compile my code I always get the following error with a lot of text following:
"Undefined symbols for architecture x86_64:"
I know it's a common error, but I couldn't find a solution since all given answers are always specific to the code the user posted and I don't get what to do.
For the example I just used the typical "Hello World" code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
For the task.json code (I got it from the internet, I actually don't know what that is…) I typed in:
{
"version": "0.1.0",
"command": "gcc",
"args": ["-Wall", "nameoffile.cpp"],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
and again I get:
Undefined symbols for architecture x86_64:
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in HelloWorld-140a91.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-140a91.o
"std::__1::ios_base::getloc() const", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in HelloWorld-140a91.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-140a91.o
.......
So what am I doing wrong? When running the code on tutorialspoint.com it works perfectly fine. I also tried to compile my file with the OS X terminal. Same error…
So what do I have to do to make it work?
Thank you in advance :)