title: Xcode error: "2 duplicate symbols for architecture x86_64"
body: <p>I keep getting this error when I try to compile and have no idea why</p>
  
  <pre><code>Ld /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Products/Debug/BATTLESHIP normal x86_64
      cd /Users/Itunes/Desktop/Programs/CMPSC122/BATTLESHIP
      setenv MACOSX_DEPLOYMENT_TARGET 10.7
      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Products/Debug -F/Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Products/Debug -filelist /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/BATTLESHIP.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -o /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Products/Debug/BATTLESHIP
  
  duplicate symbol __ZlsRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEERK5Point in:
      /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/main.o
      /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/Board.o
  duplicate symbol __ZlsRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEERK5Point in:
      /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/main.o
      /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/Ship.o
  ld: 2 duplicate symbols for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>My headers  and .cpp files are</p>
  
  <pre><code>Board.h
  // Board.h - Board class declaration
  
  #pragma once
  
  #include "Point.h"
  using namespace std;
  
  
  #define HIT 'X'
  #define SHIP 'S'
  #define MISS 'O'
  #define WATER '~'
  
  class Board
  {
  public:
      // Constructor
      Board();
  
      // Function which prints an image of the board showing hits ( X ) and misses ( O )
      void PrintBoard();
  
  
      // Resets the board for both players before new games begin
      void ResetBoard();
  
      // Marks both boards after each guess
      void MarkBoard(bool hit, Point guessCoordinate);
  
      // Returns TRUE if the user has guessed the given coordinate
      bool CheckGuess( Point guessCoordinate );
  
  
  private:
      // Board used for determining whether the user has guessed a certain position yet or not 
      bool playerBoard[BOARD_WIDTH][BOARD_LENGTH] = {false};
      // Board used soley for output
      // KEY: 0 = not yet guessed, 1 = hit, 2 = miss
      // intialize all spaces to 0 to show that no guesses have been made yet
      int outputBoard[10][10] = { 0 };
  
  };
  </code></pre>
  
  <p>Board.cpp</p>
  
  <pre><code>// Board.cpp - Board class function implementation
  
  #include "Board.h"
  
  
  Board::Board()
  {
  
  }
  
  
  // Prints the output board to console
  void Board::PrintBoard()
  {
      // Print column numbers
      cout &lt;&lt; "   \t" &lt;&lt; " " &lt;&lt; 1;
      for( int number = 2; number &lt; 11; number++)
          cout &lt;&lt; " " &lt;&lt; number;
      cout &lt;&lt; endl;
  
      // Print board itself
      // i = row number, j = column number
      for( int i = 0; i &lt; 10; i++)
      {
          // int i can double as a row and column counter for checking if a space has been hit
  
          /*cout &lt;&lt; " \t";
          // Print row lines
          for( int k = 1; k &lt; 11; k++)
              cout &lt;&lt; " __";*/
          cout &lt;&lt; endl;
          // Print row number
          cout &lt;&lt; i+1 &lt;&lt; " ";
          cout &lt;&lt; "\t";
          // Print columns 
          for( int j = 0; j &lt; 10; j++)
          {
              cout &lt;&lt; "|";
  
              // INSERT CODE THAT PLACES X OR O IF GUESS IS HIT OR SHIP
              if( outputBoard[i][j] == 0 )
                  cout &lt;&lt; WATER;
              if( outputBoard[i][j] == 1 )
                  cout &lt;&lt; HIT;
              if( outputBoard[i][j] == 2 )
                  cout &lt;&lt; MISS;
  
          }
          cout &lt;&lt; "|";
          cout &lt;&lt; endl;
      }
      cout &lt;&lt; endl;
  }
  
  
  void Board::MarkBoard(bool hit, Point guessCoordinate)
  {
      // First mark the board to show the player has guessed this coordinate
      playerBoard[guessCoordinate.X][guessCoordinate.Y] = true;
  
      if( hit == true )
      {
          // Show that the player hit a ship
          outputBoard[guessCoordinate.X][guessCoordinate.Y] = 1;
      }
      else
      {
          // Show that the player missed the ship
          outputBoard[guessCoordinate.X][guessCoordinate.Y] = 2;
      }
  }
  
  
  bool Board::CheckGuess(Point guessCordinate)
  {
      bool previouslyGuessed = false;
  
      // If the given point has already been guessed, make the function return true
      if( playerBoard[guessCordinate.X][guessCordinate.Y] )
      {
          previouslyGuessed = true;
      }
  
      else
      {
          previouslyGuessed = false;
      }
  
      return previouslyGuessed;
  }
  </code></pre>
  
  <p>Ship.h</p>
  
  <pre><code>#pragma once
  
  #include &lt;string&gt;
  #include "Point.h"
  using namespace std;
  
  #define SHIP_TYPES 5
  #define MAX_LENGTH 5
  
  
  
  enum DIRECTION {HORIZONTAL,VERTICAL};
  
  
  
  class Ship
  {
  public:
      // Constructor
      Ship();
  
      // Function to initially set all ship to the correct values
      void LoadShips( Ship ship[SHIP_TYPES] );
  
      // Function which gives ships their location points and placement orientation
      void FillShipData( DIRECTION direction, Point coordinate );
  
      bool isSunk();
  
      bool isHit( Point guess, Ship ship[SHIP_TYPES] );
  
      string GetName()
      { return Name; }
  
  
  
  private:
      // Ship name
      string Name;
      // How many spaces the ship occupies
      int Length;
      // Determines whether a ship lies vertically or horizontally on the board
      DIRECTION Direction;
      // Holds the coordinates that the ship occupies
      Point spaceOccupied[MAX_LENGTH];
  
  };
  </code></pre>
  
  <p>Ship.cpp</p>
  
  <pre><code>#include "Ship.h"
  
  
  Ship::Ship()
  {
  
  }
  
  
  void Ship::LoadShips(Ship ship[SHIP_TYPES])
  {
      //Sets the default data for the ships
      //we plan to include in the game
      //IMPORTANT!! &gt; MUST MATCH SHIP_TYPES -Default=5 (0-4)
      ship[0].Name = "Cruiser"; ship[0].Length = 2;
      ship[1].Name = "Frigate"; ship[1].Length = 3;
      ship[2].Name = "Submarine"; ship[2].Length = 3;
      ship[3].Name = "Escort"; ship[3].Length = 4;
      ship[4].Name = "Battleship"; ship[4].Length = 5;
  }
  
  
  
  
  
  
  void Ship::FillShipData( DIRECTION direction, Point coordinate )
  {
      Direction = direction;
      int x,y;
  
      // If the ship will be laid horizontally, give it the initial point plus the x-coordinates to its right 
      if( Direction == HORIZONTAL )
      {
          while( coordinate.X+Length &gt;= BOARD_WIDTH || coordinate.X &lt; 0 || coordinate.Y &lt; 0 || coordinate.Y &gt;= BOARD_LENGTH )
          {
              cout &lt;&lt; "Your ship will not be entirely on the board when placed this way. Please choose a new row number and column number separated by a space (ex: x y): ";
              cin &gt;&gt; x &gt;&gt; y;
              coordinate.X = x;
              coordinate.Y = y;
  
          }
  
          for( int i = 0; i &lt; Length; i++ )
          {
              spaceOccupied[i] = coordinate;
              coordinate.X++;
          }
      }
  
      // If the ship will be laid vertically, give it the initial point plus the y-coordinates below it
      else
      {
          // Be sure the give point will contain and the ship
          while( coordinate.Y+Length &gt;= BOARD_LENGTH || coordinate.X &lt; 0 || coordinate.Y &lt; 0 || coordinate.X &gt;= BOARD_WIDTH )
          {
              cout &lt;&lt; "Your ship will not be entirely on the board when placed this way. Please choose a new row number and column number separated by a space (ex: x y): ";
              cin &gt;&gt; x &gt;&gt; y;
              coordinate.X = x;
              coordinate.Y = y;
  
          }
  
          for( int i = 0; i &lt; Length; i++ )
          {
              spaceOccupied[i] = coordinate;
              coordinate.Y++;
          }
      }
  }
  
  
  
  
  
  
  // use throwaway to call, one user's guess and the other user's ships
  // 
  bool Ship::isHit( Point guess, Ship ship[SHIP_TYPES] )
  {
      bool hit = false;
  
      // For loop to examine each ship
      for( int i = 0; i &lt; SHIP_TYPES &amp;&amp; hit==false; i++ )
      {
          // For loop to go through each point the ship occupies
          for( int j = 0; j &lt; ship[i].Length &amp;&amp; hit==false; j++ )
          {
              // If the player's guess matches a point the ship is located on, it has been hit
              if( ship[i].spaceOccupied[j] == guess )
              {
                  hit = true;
  
                  // Inform player they landed a hit
                  cout &lt;&lt; "Ship: " &lt;&lt; ship[i].Name &lt;&lt; " has been hit!\n";
              }
          }
      }
  
      // If the player has missed all ships, inform them
      if( hit == false )
          cout &lt;&lt; "Missed.\n";
  
  
      return hit;
  }
  </code></pre>
  
  <p>And finally Point.h</p>
  
  <pre><code>#pragma once
  
  #include &lt;iostream&gt;
  using namespace std;
  
  #define BOARD_LENGTH 10
  #define BOARD_WIDTH 10
  
  struct Point
  {
      // A location on the grid defined
      // by X(horizontal) Y(vertical) coordinates
      int X;
      int Y;
  
      bool operator == (const Point&amp; compareTo) const
      {
          return ( (X == compareTo.X) &amp;&amp; (Y == compareTo.Y) );
      }
  
  };
  
  
  
  ostream&amp; operator &lt;&lt;(ostream&amp; out, const Point&amp; myPoint)
  {
      out &lt;&lt; "(" &lt;&lt; myPoint.X &lt;&lt; "," &lt;&lt; myPoint.Y &lt;&lt; ")";
      return out;
  }
  </code></pre>
  
  <p>My main function simply includes Board.h and Ship.h with no function declarations.
  Any help would be greatly appreciated! </p>