How to avoid multiple definitions when defining test doubles
<p>I am new to unit testing and I am trying to define a test double for a function that I am trying to define. It probably doesn't make much difference, but I am using IAR for a Cortex ARM M3 with the included compiler.</p>

<p>In the function that I'm trying to test, I make a call to a function that sends a message over a serial interface.
Here is some pseudocode to illustrate what I am trying to accomplish :</p>

<pre><code>#ifdef UNIT_TEST
#include "MessageController.h"
#else
#include "FakeMessageController.h"
#endif

uint8 FunctionToTest(....)
{
  uint8 data[100];
  uint8 error;

  //Prepare data to send here
  SendMessage(data);

  if (error)  return 1;
  else return 0;
}
</code></pre>

<p>I have created a copy of the original file that contained the SendMessage function and made mofications to it in another file. I thought that I could change the function that is called through the #ifdef statements, however, that is ot the case.</p>

<p>I get the following error for multiple definitions</p>

<pre><code>Error[Li006]: duplicate definitions for .... ; in "......\Tests\Debug\Obj\MessageController.o", and "....\dvlp\Debug\Tests\Debug\Obj\FakeMessageController.o"
</code></pre>

<p>I fully understand the reason why the linker is giving my this error, but is there a workaround to this problem? Or some way of tricking the linker into using the correct function?
I can't modify the test function since it is a link to the original file in my project.</p>