Code to reverse a string: "Undefined symbols for architecture x86_64" : <p>I'm writing a function to reverse a string, but I keep on getting the error "Undefined symbols for architecture x86_64" when compiling (clang). Here is my code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

char* reverse(string input);

int main() {
  char* output;
  output = reverse("abcd");
  cout &lt;&lt; *output;
}

char* reverse(char* input) {
  char* reversed;
  reversed = new char(sizeof(input) - 1);
  for(int i = 0; i != '\0'; i++) {
    char* j = reversed + sizeof(input - 1);
    input[i] = *j;
    j++;
  }
  return reversed;
}
</code></pre>

<p>Specifically, this is what the compiler prints:</p>

<pre><code>Undefined symbols for architecture x86_64:
  "reverse(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)", referenced from:
      _main in test-c5860d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Error 1
</code></pre>

<p>I'm sure that there are also logic errors in my code, but I'd like to have it compile and run at least before I debug those. Thanks!</p>
