title: Mac OS - VS Code Insiders - Code Runner: Undefined symbols for architecture arm64
body: <p>I've been stuck on this issue in the past week. when I compiled the code with the VS Code Insiders - Code Runner Extension or the command: clang++ -std=c++14 main.cpp, it gives me the below error:</p>
  <pre><code>Undefined symbols for architecture arm64:
    &quot;LinkedList::insertHead(int)&quot;, referenced from:
        _main in main-6d6a24.o
    &quot;LinkedList::insertTail(int)&quot;, referenced from:
        _main in main-6d6a24.o
    &quot;operator&lt;&lt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, LinkedList const&amp;)&quot;, referenced from:
        _main in main-6d6a24.o
  ld: symbol(s) not found for architecture arm64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  <p>However, I was able to compile the code with the Makefile below:</p>
  <pre><code>all: main
  
  main: main.o linkedList.o
      clang++ -std=c++14 -o $@ $^
  
  main.o: main.cpp linkedList.h
      clang++ -std=c++14 -c $&lt;
  
  linkedList.o: linkedList.cpp linkedList.h
      clang++ -std=c++14 -c $&lt;
  
  clean:
      rm -f main *.o
      rm -f linkedList *.o
  </code></pre>
  <p>And also it would work if I put the int main() {} inside the linkedList.cpp.
  I guess maybe there are some kind of linker issue? It's been mentioned a lot when I searched the error.</p>
  <p>Here is the code:
  main.cpp:</p>
  <pre><code>#include &quot;linkedList.h&quot;
  #include &lt;iostream&gt;
  
  int main() {
    LinkedList l;
    LinkedList l2;
  
    for (int i = 0; i &lt; 10; i++) {
      l.insertHead(i);
    }
  
    for (int i = 0; i &lt; 10; i++) {
      l2.insertTail(i);
    }
  
    std::cout &lt;&lt; l &lt;&lt; std::endl;
    std::cout &lt;&lt; l2 &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>
  <p>linkedList.h:</p>
  <pre><code>#include &lt;iostream&gt;
  
  struct Node {
    int data;
    Node *next = nullptr;
  };
  
  class LinkedList {
   private:
    Node *head;
    Node *tail;
    void inserFirst(int);
    Node *createNode(int);
  
   public:
    void insertHead(int);
    void insertTail(int);
    friend std::ostream &amp;operator&lt;&lt;(std::ostream &amp;out, const LinkedList &amp;list);
  };
  </code></pre>
  <p>linkedList.cpp:</p>
  <pre><code>#include &quot;linkedList.h&quot;
    
  void LinkedList::inserFirst(int item) {
    Node *n = createNode(item);
    head = n;
    tail = n;
  }
  
  Node* LinkedList::createNode(int item) {
    Node *n = new Node;
    n-&gt;data = item;
    n-&gt;next = nullptr;
    return n;
  }
  
  void LinkedList::insertHead(int item) {
    if (head == nullptr) {
      inserFirst(item);
    } else {
      Node *n = createNode(item);
      n-&gt;next = head;
      head = n;
    }
  }
  
  void LinkedList::insertTail(int item) {
    if (head == nullptr) {
      inserFirst(item);
    } else {
      Node *n = createNode(item);
      tail-&gt;next = n;
      tail = n;
    }
  }
  
  std::ostream &amp;operator&lt;&lt;(std::ostream &amp;out, const LinkedList &amp;list) {
    Node *n = list.head;
    while (n != nullptr) {
      out &lt;&lt; n-&gt;data;
      n = n-&gt;next;
    }
    return out;
  }
  </code></pre>
  <p>What made me confused is since the code can be compiled with the Makefile, why wouldn't it be compiled with the code runner?</p>
  <p>Just a quick update: I tested the code on CLion and it was compiled, so I'm gonna reinstall the code runner extension on Vs Code to see if it fixes the problem.</p>