title: How to declare global variable in C?
body: <p>I am starting to use C. I have problem to define global variable. E.g. <code>platformID</code> is used in <code>install.c</code>. I declared in <code>main.c</code> but still I got error :</p>
  
  <pre><code>install.c|64|error: 'platformID' undeclared (first use in this function)
  </code></pre>
  
  <p><strong>main.c:</strong></p>
  
  <pre><code>#ifdef __APPLE__
  #include &lt;OpenCL/opencl.h&gt;
  #else
  #include &lt;CL/cl.h&gt;
  #endif
  
   cl_int err;//the openCL error code/s
   cl_platform_id platformID;//will hold the ID of the openCL available platform
   cl_uint platformsN;//will hold the number of openCL available platforms on the machine
   cl_device_id deviceID;//will hold the ID of the openCL device
   cl_uint devicesN; //will hold the number of OpenCL devices in the system
  
  #include "include/types.h"
  #include "include/gaussian.h"
  #include "include/args.h"
  #include "include/files.h"
  #include "refu/Time/rfc_timer.h"
  #include &lt;stdio.h&gt;
  </code></pre>
  
  <p>...</p>
  
  <p><strong>install.c</strong></p>
  
  <pre><code>#include "include/types.h"
  #include "include/gaussian.h"
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  #include &lt;sys/types.h&gt; // mkdir
  #include &lt;sys/stat.h&gt; // mkdir
  
  #ifdef __APPLE__
  #include &lt;OpenCL/opencl.h&gt;
  #else
  #include &lt;CL/cl.h&gt;
  #endif
  
  #define MAX_SOURCE_SIZE (1048576) //1 MB
  #define MAX_LOG_SIZE    (1048576) //1 MB
  
  // Install: build kernel
  bool buildKernels(char ** path,FILES * files, int count )
  {
  
      int c; // number of file
  
      if(clGetPlatformIDs(1, &amp;platformID, &amp;platformsN) != CL_SUCCESS)
      {
          printf("Could not get the OpenCL Platform IDs\n");
          return false;
      }
      if(clGetDeviceIDs(platformID, CL_DEVICE_TYPE_DEFAULT, 1,&amp;deviceID, &amp;devicesN) != CL_SUCCESS)
      {
          printf("Could not get the system's OpenCL device\n");
          return false;
      }
  </code></pre>
  
  <p>...</p>
  
  <p>How to declare the global variable so it is visible in the included file? Can you help to fix it?</p>