title: C++ linking error with multiple definition on linux
body: <p>I am trying to compile a code and it’s getting a linking error with multiple definitions. Unfortunately, I am not able to fix it and any help would be appreciated.</p>
  
  <p>I have following files:
  Header files: CEST.h;  CEST_UI.h;  GlobalVariable.h;<br>
  Source file: CEST.cpp;  CEST_UI.cpp;  GlobalVariable.cpp</p>
  
  <p>All parameters, which are claimed to have multiple definitions, are defined in “GlobalVariable.h” and initialized in “GlobalVariable.cpp”.</p>
  
  <p>I am including “GlobalVariable.h” twice: once in CEST.cpp and second time in CEST_UI.cpp.</p>
  
  <p>I was thinking that the following guard in “GlobalVariable.h” would have protected me aginst multiple definition linking error:</p>
  
  <pre><code># ifndef GLOBALVARIABLE_H
  #define GLOBALVARIABLE_H
  ………….
  ………….
  #endif
  </code></pre>
  
  <p>I am also attaching “GlobalVariable.h” and “GlobalVariable.cpp” so that you can have a look.</p>
  
  <p>In “GlobalVariable.h”</p>
  
  <pre><code># ifndef GLOBALVARIABLE_H
  #define GLOBALVARIABLE_H
  
      #include &lt;vector&gt;
      ////////////////////////////////////////
      extern long lFA_MTPulse;
      extern long lNoOfMTPulses;
      extern long ltDK_MTPulse_Duration_us;
      //extern long ltDK_MTPulse_Delay_us;
      extern long ltDK_Wait_After_MT_us;
      extern long ltDK_Wait_After_MTSpoil_us;
      extern long lNoOfMTPulses_PerRTEB;
      extern long ltDK_PreAcqCESTPulseTime_ms;
      extern long ltDK_PreAcqCESTPulseTime_us;
      extern long lTest_XgradStrength;
      //double TR_MTPulse_Remain = 0.0;                                                                   // CEST This will be calculated later 
      long ltDK_TR_MTPulse_us;
      long ltDK_TimeNeeded_for_sMTCSpoilerOnly;
      long ltDK_MTBlockTime_DK;
  
      ////////////////////////////////////////
      extern double dBWTimeProd;
      extern double dSpoilerCTRL;
      extern double dOffResonance_Rel;
      ////////////////////////////////////////
      long No_of_Samples = (long)512;                                                                     // CEST
      long lNo_of_MTPulses_PreAcq;
      //static sRF_PULSE  sRfMSat1("sRfMSat");                                                        // CEST("sRfMSat")
  
      extern long lNoOfKSpaceAcq_PerCEST_ArrayValues[];
  
  
  #endif
  </code></pre>
  
  <p>In GlobalVariable.cpp</p>
  
  <pre><code>// NOTE: usually name of any parameters is prefixed by type e.g. 
  // I am introducing another parameter with prefix "ltDK_" for "long-time" parameter 
  //
  long lFA_MTPulse = 100;
  long lNoOfMTPulses = 1;
  long ltDK_MTPulse_Duration_us = 10000;
  //long ltDK_MTPulse_Delay_us = 10000;
  long ltDK_Wait_After_MT_us = 0;
  long ltDK_Wait_After_MTSpoil_us = 0;
  long ltDK_PreAcqCESTPulseTime_ms = 3500;                                                // in micro sec 
  long ltDK_PreAcqCESTPulseTime_us = (long)((double)ltDK_PreAcqCESTPulseTime_ms*1000);    // in milli sec
  long lTest_XgradStrength = 0;
  
  long lNoOfMTPulses_PerRTEB = 30;
  double dBWTimeProd = 1.79;
  double dSpoilerCTRL = 1.0;
  double dOffResonance_Rel = 0.0;
  long lNoOfKSpaceAcq_PerCEST_ArrayValues[5] = {1, 3, 5, 7, 9};
  </code></pre>