title: How do I add cpp file to an arduino project?
body: <p>I am trying to add a cpp file to arduino project that has the following setup...</p>
  
  <pre><code>project 
  --folder
    --foo.h
    --foo.cpp
  --project.ino
  </code></pre>
  
  <p>I have a <code>#include "folder/foo.h</code> at the top of <code>project.ino</code>. However while the header provides the prototype of the function, the function definition is in the cpp file. When I try to compile the code using the Arduino IDE, it fails with error
  <code>Undefined reference to 'bar()'</code>
  and <code>bar()</code> is located in <code>foo.cpp</code></p>
  
  <p>I looked at <a href="http://forum.arduino.cc/index.php?topic=219439.0" rel="noreferrer">this</a> but I do not have a setting for <code>sketch/import library</code> (however I do have <code>sketch/include library</code>, however I did not see anything close to using a custom folder location)</p>
  
  <p>I looked at <a href="https://www.arduino.cc/en/Hacking/LibraryTutorial" rel="noreferrer">this</a> too. But same as above, that setting does not exist in my ide. (Which I downloaded recently)</p>
  
  <p>Code</p>
  
  <pre><code>//project.ino
  #include "folder/foo.h"
  void setup() {
      Serial.begin(9600);
  }
  void loop() {
      bar();
  }
  </code></pre>
  
  <pre><code>//folder/foo.h
  #include "Arduino.h"
  void bar();
  </code></pre>
  
  <pre><code>//folder/foo.cpp
  #include "foo.h"
  
  void bar() {
      Serial.println("bar");
  }
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>/tmp/ccNTRFfU.ltrans0.ltrans.o: In function `loop':
  /home/temporary/project/project.ino:9: undefined reference  to `bar()'
  collect2: error: ld returned 1 exit status
  exit status 1
  </code></pre>
  
  <p>What I would expect to happened is a way to link the cpp folder without having to put all the files in the same root folder of the project. </p>
  
  <p>--Edit 1: 
  added code</p>
  
  <p>--Edit 2: 
  added <code>#include "Arduino.h"</code></p>
  
  <p>--Edit 3:
  added <code>Serial.begin(9600);</code></p>