title: Handling duplicate symbols for peripheral registers when testing embedded C++ code using googletest
body: <p>I'm developing a hobby project for MSP430F5529 using C++ and testing using googletest. I'm a true beginner both at C/C++, microcontrollers/embedded and googletest.</p>
  
  <p>The peripherals on the MSP are controlled via registers and TI provides a header <code>&lt;msp430.h&gt;</code> that includes a processor specific header, <code>msp5529.h</code>, in my case and that header defines a large number of constants for bits etc but it also declares the registers available on the microcontroller for example <code>UCA1CTL1</code>used to setup serial communication.</p>
  
  <p>When I compile for build <code>&lt;msp430.h&gt;</code> is included in <code>UART.h</code> for example and everything works as intended. When testing however I want to include a testable version of <code>&lt;msp430.h&gt;</code> which we can call <code>testable_msp430.h</code>.</p>
  
  <p>So basically we have the following:</p>
  
  <p><strong>UART.h</strong></p>
  
  <pre><code>#ifndef TESTING
  #include &lt;msp430.h&gt;
  #else 
  #include "testable_msp430.h"
  #endif
  </code></pre>
  
  <p><strong>testable_msp430.h</strong></p>
  
  <pre><code>int UCA1CTL1;
  
  *A bunch of other declarations*
  </code></pre>
  
  <p><strong>test_UART.cpp</strong></p>
  
  <pre><code>#include UART.h
  
  *A bunch of tests*
  </code></pre>
  
  <p><strong>UART.cpp</strong></p>
  
  <pre><code>#include UART.h
  
  *A bunch of source*
  </code></pre>
  
  <p>The problem is that when compiling this for test by running <code>g++ -std=c++11 src/UART.cpp test/test_UART.cpp -lgtest -lgtest_main -pthread -o testOutput -DTESTING</code> I get a link error stating </p>
  
  <pre><code>duplicate symbol _UCA1CTL1 in:
      /var/folders/yr/mkwg3mhs1nl93l35x6t55vz80000gn/T/UART-772fab.o
      /var/folders/yr/mkwg3mhs1nl93l35x6t55vz80000gn/T/test_UART-2e1a90.o
  </code></pre>
  
  <p>which makes sense since <code>UCA1CTL1</code>is defined in both the compilation unit for <code>UART.cpp</code>and <code>test_UART.cpp</code>. My question is therefore how memory mapped registers are usually handled to be able to test against/using them? </p>
  
  <p>Thanks in advance!</p>