title: Global struct c++
body: <p>I'm aware that this question has been asked multiple times before, but I can't get this to work. For a special case I need to have a global struct that will be filled in one file, and read in another.</p>
  
  <p>The following code gives me a linking error:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_camera_data", referenced from:
        MyCameraData::return_sensor_shift() in extra-424af5.o
  ld: symbol(s) not found for architecture x86_64
  clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>common.h:</p>
  
  <pre><code>#ifndef COMMON_H
  #define COMMON_H
  struct MyCameraData
  {
      float sensor_shift;
      float return_sensor_shift();
  };
  extern MyCameraData camera_data;
  #endif
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "common.h"
  #include &lt;iostream&gt;
  
  int main(){
      MyCameraData camera_data;
  
      camera_data.sensor_shift = 5.0;
  
      std::cout &lt;&lt; camera_data.return_sensor_shift() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>extra.cpp:</p>
  
  <pre><code>#include "common.h"
  
  float MyCameraData::return_sensor_shift(){
      return camera_data.sensor_shift;
  }
  </code></pre>
  
  <p>There must be something I'm overlooking. Any ideas?</p>