Compiling C++ in OSX terminal: Undefined symbols for architecture x86_64 : <p>I'm writing code for a class project and I did it all in Xcode, which worked fine. I was able to compile w/ arguments in Xcode and get output. However, when I try to compile it in terminal, I keep getting this error (I'm also not sure if I'm compiling it correctly):</p>

<pre><code>francis-mbp:CS280-Assignment1 fren$ gcc /Users/fren/Desktop/CS280-Assignment1/main.cpp -o main 
/Users/fren/Desktop/CS280-Assignment1/main.cpp:31:32: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    list&lt;string&gt;::iterator iter=lineToPrint.begin();
                               ^
/Users/fren/Desktop/CS280-Assignment1/main.cpp:32:19: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    int charLimit = 60;
                  ^
2 warnings generated.
Undefined symbols for architecture x86_64:
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::compare(char const*) const", referenced from:
      _main in main-b9d962.o
  "std::__1::locale::has_facet(std::__1::locale::id&amp;) const", referenced from:
      std::__1::basic_filebuf&lt;char, std::__1::char_traits&lt;char&gt; &gt;::basic_filebuf() in main-b9d962.o
  "std::__1::locale::use_facet(std::__1::locale::id&amp;) const", referenced from:
      std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp; std::__1::endl&lt;char, std::__1::char_traits&lt;char&gt; &gt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;) in main-b9d962.o
      std::__1::basic_filebuf&lt;char, std::__1::char_traits&lt;char&gt; &gt;::imbue(std::__1::locale const&amp;) in main-b9d962.o
      std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp; std::__1::__put_character_sequence&lt;char, std::__1::char_traits&lt;char&gt; &gt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, char const*, unsigned long) in main-b9d962.o
      std::__1::basic_filebuf&lt;char, std::__1::char_traits&lt;char&gt; &gt;::basic_filebuf() in main-b9d962.o
  "std::__1::ios_base::getloc() const", referenced from:
      std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp; std::__1::endl&lt;char, std::__1::char_traits&lt;char&gt; &gt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;) in main-b9d962.o
      std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp; std::__1::__put_character_sequence&lt;char, std::__1::char_traits&lt;char&gt; &gt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, char const*, unsigned long) in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::erase(unsigned long, unsigned long)", referenced from:
      Line::addWord(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::__init(char const*, unsigned long)", referenced from:
      Line::addWord(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in main-b9d962.o
      Line::printLine(int) in main-b9d962.o
      _main in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::__init(char const*, unsigned long, unsigned long)", referenced from:
      std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; std::__1::operator+&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, char const*) in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::__init(unsigned long, char)", referenced from:
      std::__1::ostreambuf_iterator&lt;char, std::__1::char_traits&lt;char&gt; &gt; std::__1::__pad_and_output&lt;char, std::__1::char_traits&lt;char&gt; &gt;(std::__1::ostreambuf_iterator&lt;char, std::__1::char_traits&lt;char&gt; &gt;, char const*, char const*, char const*, std::__1::ios_base&amp;, char) in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::append(char const*, unsigned long)", referenced from:
      std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; std::__1::operator+&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, char const*) in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::assign(char const*)", referenced from:
      Line::addWord(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in main-b9d962.o
      _main in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::push_back(char)", referenced from:
      _main in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::basic_string(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;)", referenced from:
      Line::addWord(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in main-b9d962.o
      std::__1::list&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt;::push_back(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in main-b9d962.o
      std::__1::list&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt;::insert(std::__1::__list_const_iterator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, void*&gt;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in main-b9d962.o
      Line::checkBack() in main-b9d962.o
      _main in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::basic_string(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, unsigned long, unsigned long, std::__1::allocator&lt;char&gt; const&amp;)", referenced from:
      Line::addWord(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in main-b9d962.o
  "std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::~basic_string()", referenced from:
      Line::addWord(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in main-b9d962.o
      std::__1::list&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt;::pop_back() in main-b9d962.o
      std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; std::__1::operator+&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, char const*) in main-b9d962.o
      Line::printLine(int) in main-b9d962.o
      std::__1::list&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt;::pop_front() in main-b9d962.o

      std::__1::list&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt;::push_back(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in main-b9d962.o
      std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; std::__1::operator+&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, char const*) in main-b9d962.o
      std::__1::list&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt;::insert(std::__1::__list_const_iterator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, void*&gt;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in main-b9d962.o
      Line::printLine(int) in main-b9d962.o
      Line::popBack(int) in main-b9d962.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
francis-mbp:CS280-Assignment1 fren$ 
</code></pre>

<p>Here's the code for my project (doesn't include main bc of character limit): </p>

<pre><code>#include &lt;iostream&gt;
#include&lt;string&gt;
#include&lt;vector&gt;
#include&lt;sstream&gt;
#include&lt;fstream&gt;
#include&lt;algorithm&gt;
#include&lt;queue&gt;
#include&lt;list&gt;
#include&lt;iterator&gt;
#include&lt;ctype.h&gt;
using namespace std;


/*
 Class defining data structure that holds linked list containing words to be output
 Contains words on a per-line basis (Empties after each line is printed)
 Handles list operations
 */
class Line
{
public:
    list&lt;string&gt; lineToPrint;
    list&lt;string&gt;::iterator iter=lineToPrint.begin();
    int charLimit = 60;
    string spaceToInsert;

    int totalChars;
    int totalSpaces;
    int numWords;
    int placesForSpaces;
    int spacePerPlace;
    int extraSpaces;

    void addWord (string word);
    void reset (void);
    void changeLimit (int newLimit);
    void printLine (int endOfParagraph);
    void calculateSpaces(void);
    void newParagraph(void);
    void popBack(int type);
    string checkBack(void);
};

void Line::addWord(string word) {

    cout &lt;&lt; "adding word: " &lt;&lt; word &lt;&lt; endl;
    string firstHalfWord;
    string secondHalfWord;
    int numToTruncate;
    int splittingWord = 1;
    lineToPrint.push_back(word);
    totalChars += word.length();
    numWords ++;
    calculateSpaces();
    if(((totalChars &gt; charLimit) &amp;&amp; (numWords &gt;= 1)) || ((totalSpaces &lt; placesForSpaces) &amp;&amp; (spacePerPlace == 0))) {
        splittingWord = 0;
        lineToPrint.pop_back();
        numToTruncate = totalChars - (charLimit - placesForSpaces - 1);
        if(numToTruncate &gt; word.length()) {
            cout &lt;&lt; numToTruncate &lt;&lt; " " &lt;&lt; word.length();
            cout &lt;&lt; "error" &lt;&lt; endl;
        } else {
            secondHalfWord = word.substr(word.length() - numToTruncate);
            firstHalfWord = word.erase(word.length() - numToTruncate) + "-";
        }
        lineToPrint.push_back(firstHalfWord);

        totalChars -= (word.length() + secondHalfWord.length());

        totalChars += firstHalfWord.length();


        calculateSpaces();
    }

    if((spacePerPlace &lt;= 2 &amp;&amp; extraSpaces&lt;= placesForSpaces)||(spacePerPlace == 3 &amp;&amp; extraSpaces == 0)) {
        if(spacePerPlace == 1){
            spaceToInsert = " ";
        } else if (spacePerPlace == 2) {
            spaceToInsert = "  ";
        } else if (spacePerPlace == 3) {
            spaceToInsert = "   ";
        }

        iter++;
        for(int j = placesForSpaces; j &gt; 0; j--) {
            //cout &lt;&lt; "inserting " &lt;&lt; spacePerPlace &lt;&lt; " spaces!" &lt;&lt; endl;
            lineToPrint.insert(iter, spaceToInsert);
            totalSpaces -= spacePerPlace;
            if(extraSpaces != 0){
                lineToPrint.insert(iter, " ");
                totalSpaces --;
                extraSpaces --;
            }
            iter++;
        }
        printLine(1);
    }
    if(splittingWord == 0 &amp;&amp; secondHalfWord.length() &gt; charLimit){
        iter = lineToPrint.begin();
        addWord(secondHalfWord);
    } else if (splittingWord == 0 &amp;&amp; secondHalfWord.length() &lt;= charLimit) {
        lineToPrint.push_back(secondHalfWord);
        totalChars += secondHalfWord.length();
        numWords ++;
    }
    iter = lineToPrint.begin();
    splittingWord = 1;
}

//Resets the list and variables for calculating spaces to insert
void Line::reset(void) {
    lineToPrint.clear();
    totalChars = 0; totalSpaces = 0; numWords = 0; placesForSpaces = 0;
}

//Changes the variable limit used in space insert calculations
void Line::changeLimit(int newLimit) {
    //cout &lt;&lt; "Changing Limit to: " &lt;&lt; newLimit &lt;&lt; endl;
    charLimit = newLimit;
}

//Makes calculations for variables used in space insertion calculations
void Line::calculateSpaces(void) {
    //cout &lt;&lt; "calculating spaces..." &lt;&lt; endl;
    totalSpaces = charLimit - totalChars;

    if (numWords == 1 &amp;&amp; totalChars &gt;= charLimit) {
        placesForSpaces = 0;
        spacePerPlace = 0;
    } else {
        if(numWords == 1){
            placesForSpaces = 1;
        } else {
            placesForSpaces = numWords - 1;
        }
        spacePerPlace = totalSpaces/placesForSpaces;
        extraSpaces = totalSpaces%placesForSpaces;
    }

    //cout &lt;&lt; "totalChars: "&lt;&lt; totalChars &lt;&lt;" totalSpaces: "&lt;&lt; totalSpaces &lt;&lt; " numWOrds: " &lt;&lt; numWords &lt;&lt; " placesFOrSpaces: " &lt;&lt; placesForSpaces &lt;&lt; " spacePerPlace: " &lt;&lt; spacePerPlace &lt;&lt; " extraSpaces: " &lt;&lt; extraSpaces &lt;&lt; endl;

}

//Prints the list (with spaces included)
//Takes int argument; 0 = end of paragraph, 1 = not end of paragraph
void Line::printLine(int endOfParagraph) {
    //p1cout &lt;&lt; "character limit: " &lt;&lt; charLimit &lt;&lt; endl;
    if(endOfParagraph == 1) {
        cout &lt;&lt; "printing line NOT end of paragraph" &lt;&lt; endl;
        for(list&lt;string&gt;::iterator it = lineToPrint.begin(); it != lineToPrint.end(); it++){
            cout &lt;&lt; *it;
            lineToPrint.pop_front();
        }
    } else if (endOfParagraph == 0) {
        iter++;
        cout &lt;&lt; "printing line end of paragraph" &lt;&lt; endl;

        if (numWords != 1) {
            for(int i = placesForSpaces; i &gt;0; i--) {
                lineToPrint.insert(iter, " ");
                iter++;
            }
        }
        iter = lineToPrint.begin();
        for(list&lt;string&gt;::iterator it = lineToPrint.begin(); it != lineToPrint.end(); it++){
            cout &lt;&lt; *it;
            lineToPrint.pop_front();
        }
    }
    cout &lt;&lt; endl;
    totalChars = 0; totalSpaces = 0; numWords = 0; placesForSpaces = 0;
}

//Prints a new line to separate paragraphs
void Line::newParagraph(void){
    cout &lt;&lt; endl;
}

//Returns the string held in the back of the list
string Line::checkBack(void) {
    return lineToPrint.back();
}

//Removes a string off the back of the list
void Line::popBack(int type) {
    if(type == 1){
        string wordToPop = checkBack();
        cout &lt;&lt; "word to pop : " &lt;&lt; wordToPop &lt;&lt; endl;
        int length = wordToPop.length();
        cout &lt;&lt; "length of w2pop : " &lt;&lt; length &lt;&lt;endl;
        totalChars -= length;
    }
    //cout &lt;&lt; "popping from back: " &lt;&lt; checkBack();
    lineToPrint.pop_back();
    numWords --;
}
</code></pre>

<p>Thanks to any help</p>
