0

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 :)

Omnom
  • 1
  • 1
  • 2
  • Oh of course the answer is "read this whole book and then you know what to do". I already said that I couldn't find a general answer. Maybe I'm too dumb, but then help me instead of simply mark it as a duplicate. – Omnom Oct 15 '16 at 22:24
  • After proper one day research I came across this question http://stackoverflow.com/questions/35888702/could-not-compile-a-hello-world-cpp-in-my-osx?rq=1 which is related to this issue. The problem was, that there were still missing some command line options which are needed to link some libraries. The answer to this question http://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc describes it pretty good. tl,dr: Use 'g++' instead of 'gcc' to build PS: Thank you πάντα-ῥεῖ ( ͡° ͜ʖ ͡°) – Omnom Oct 16 '16 at 08:47

0 Answers0