title: Arduino & C: put a function and global variable in external file
body: <p>This should be a simple problem. I'm trying to split up code into two files within a sketch:</p>
  
  <p>test.ino:</p>
  
  <pre><code>void setup(){}
  void loop(){ fn(); }
  </code></pre>
  
  <p>test.c:</p>
  
  <pre><code>char myChar = '?';
  void fn(){ myChar++; }
  </code></pre>
  
  <p>I've tried using a test.h file with various configurations such as having the lines:</p>
  
  <ul>
  <li><code>extern char myChar;</code>,</li>
  <li><code>char myChar;</code></li>
  <li><code>void fn();</code></li>
  <li><code>extern void fn();</code></li>
  </ul>
  
  <p>And various combinations of including test.c and test.h files in the different files, but I always get one compiler error or another, such as:</p>
  
  <blockquote>
    <p>test.cpp.o:(.data.myChar+0x0): multiple definition of `myChar'</p>
    
    <p>test.c.o:(.data.myChar+0x0): first defined here</p>
  </blockquote>
  
  <p>Or</p>
  
  <blockquote>
    <p>test.cpp.o: In function `setup':</p>
    
    <p>C:\Program Files\arduino-1.0.4/test.ino:4: undefined reference to `fn()'</p>
  </blockquote>
  
  <p>I'm really pulling my hair out with this one. Any help would be greatly appreciated</p>