title: How do you add a C++ library in Xcode? (Ncurses)
body: <p>I am a beginner to Xcode and coding in general. I have this code for a snake game, but it cannot run because I do not know how to correctly install ncurses. This is the code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ncurses.h&gt;
  
  using namespace std;
  
  
  bool gameOver;
  const int width = 20;
  const int height = 20;
  int x, y, fruitX, fruitY, score;
  enum eDirection {STOP = 0, LEFT, RIGHT, UP, DOWN};
  eDirection dir;
  
  int TailX[100], TailY[100];
  int nTail = 0;
  
  void Setup()
  {
      initscr();
      clear();
      noecho();
      cbreak();
      curs_set(0);
      
      gameOver = false;
      dir = STOP;
      x = width / 2;
      y = height / 2;
      fruitX = (rand() % width) + 1;
      fruitY = (rand() % height) + 1;
      score = 0;
  }
  
  void Draw() // draw a game map
  {
      clear();
      for (int i = 0; i &lt; width + 2; i++) {
          mvprintw(0,i,&quot;#&quot;); // print top wall
      }
      cout &lt;&lt; endl;
      
      for (int i = 0; i &lt; height+2; i++)
      {
          for (int j = 0; j &lt; width+2; j++)
          {
              if (i == 0 || i==21)
                  mvprintw(i,j,&quot;#&quot;); // outside walls
              else if (j == 0 || j == 21)
                  mvprintw(i, j, &quot;#&quot;); // outside walls
              
              else if (i == y &amp;&amp; j == x)
                  mvprintw(i,j,&quot;O&quot;); // print head of snake
              else if (i == fruitY &amp;&amp; j == fruitX)
                  mvprintw(i, j, &quot;@&quot;); // print fruit
              else
                  for (int k = 0; k &lt; nTail; k++)
                  {
                      if (TailX[k] == j &amp;&amp; TailY[k] == i)
                          mvprintw(i, j, &quot;o&quot;); // print tail of snake
                  }
              }
          
      }
      mvprintw (23, 0, &quot;Score %d&quot;, score);
      refresh();
  }
  
      void Input()
  
      {
  
        keypad(stdscr, true);
        halfdelay(1);
  
        int c = getch();
  
        switch(c)
  
        {
  
          case KEY_LEFT:
            dir = LEFT;
            break;
          case KEY_RIGHT:
            dir = RIGHT;
            break;
          case KEY_UP:
            dir = UP;
            break;
          case KEY_DOWN:
            dir = DOWN;
            break;
  
          case 'Q':
            gameOver = true;
            break;
  
        }
  
      }
  
      void Logic()
  
      {
        int prevX = TailX[0];
        int prevY = TailY[0];
        int prev2X, prev2Y;
        TailX[0] = x;
        TailY[0] = y;
  
  
  
        for (int i = 1; i &lt; nTail; i++)
  
        {
  
          prev2X = TailX[i];
          prev2Y = TailY[i];
          TailX[i] = prevX;
          TailY[i] = prevY;
          prevX = prev2X;
          prevY = prev2Y;
  
        }
  
        switch(dir)
  
        {
  
          case LEFT:
            x--;
            break;
                
          case RIGHT:
            x++;
            break;
                
          case UP:
            y--;
            break;
  
          case DOWN:
            y++;
            break;
  
          default:
            break;
  
        }
  
        if(x &gt; width || x &lt; 1 || y &lt; 1 || y &gt; height)
          gameOver = true;
  
          if(x == fruitX &amp;&amp; y == fruitY)
        {
          score++;
            fruitX = (rand() % width)+1;
            fruitY = (rand() % height)+1;
          nTail++;
        }
  
        for (int i = 0; i &lt; nTail; i++)
  
          if (TailX[i] == x &amp;&amp; TailY[i] == y)
  
          {
            gameOver = true;
          }
  
      }
  
      int main()
  
      {
        Setup();
        Draw();
  
        while(!gameOver)
  
        {
          Draw();
          Input();
          Logic();
  
        }
  
        getch();
        endwin();
        return 0;
  
      }
  
  </code></pre>
  <p>I tried adding  libcurses.tbd and libncurses.tbd to Frameworks and Libraries, which got me past my initial errors of unknown variables, however the code is still not running.</p>
  <p>The message I am receiving from the compiler is
  &quot;Error opening terminal: unknown.
  Program ended with exit code: 1&quot;</p>
  <p>Please let me know how to install ncurses! I have attempted to follow the steps listed here <a href="https://ports.macports.org/port/ncurses/" rel="nofollow noreferrer">https://ports.macports.org/port/ncurses/</a> but don't know where to copy and paste the &quot;sudo port install ncurses&quot; that it tells me to. Please help I have only used the existing libraries in Xcode and am very confused with how to install a new one.</p>
  <p>If it makes any difference, my Mac system is macOS Big Sur v11.5.2 and I am working on Xcode v12.5.1</p>
  <p>thank you in advance!</p>