title: C makefile undefined-reference error
body: <p>I am having slight problems with using makefile in C. Ive been following a tutorial in a textbook, but it doesnt seem to want to work. I have three files, message_hider.c, encrypt.h and encrypt.c. When I create a makefile for these files it returns an error, but when I run each command individually it works just fine. Here are my files.</p>
  
  <p>encrypt.c</p>
  
  <pre><code>#include "encrypt.h"
  
  void encrypt(char *message) {
  char c;
  while (*message) {
  *message = *message ^ 31;
  message++;
  }
  }
  </code></pre>
  
  <p>message_hider.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "encrypt.h"
  
  int main() {
  char msg[80];
  while (fgets(msg, 80, stdin)) {
  encrypt(msg);
  printf("%s", msg);
  }
  }
  </code></pre>
  
  <p>encrypt.h</p>
  
  <pre><code>void encrypt(char *message);
  </code></pre>
  
  <p>Makefile</p>
  
  <pre><code>message_hider: message_hider.o encrypt.o
      gcc message_hider.o encrypt.o -o message_hider
  message_hider.o: message_hider.c encrypt.h
      gcc -c message_hider.c
  encrypt.o: encrypt.c encrypt.h
      gcc -c encrypt.c
  </code></pre>
  
  <p>Error message</p>
  
  <pre><code>$ make message_hider
  cc   message_hider.o   -o message_hider
  message_hider.o:message_hider.c:(.text+0x17): undefined reference to `encrypt'
  message_hider.o:message_hider.c:(.text+0x17): relocation truncated to fit: R_X86_64_PC32       against undefined symbol `encrypt'
  /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld:     message_hider.o: bad reloc address 0x0 in section `.pdata'
  /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: final link    failed: Invalid operation
  collect2: error: ld returned 1 exit status
  &lt;builtin&gt;: recipe for target 'message_hider' failed
  make: *** [message_hider] Error 1
  </code></pre>