title: Issue with time variable conflict in OpenGL 4.3 program Ubuntu 14.04 x64
body: <p>So I am getting a strange error when compiling an OpenGL 4.3 program and was hoping someone could help. I have been working on one of the recipes in the OpenGL Development Cookbook for a RippleDeformer. I am running into a compile error and am not sure how to fix it.</p>
  <p>It seems like there is a variable in the main.cpp program named <code>time</code> and also one of the OpenGL libraries also involves the <code>time.h</code> header, so that causes a problem with the declaration. I tried to change the name of the variable in the program and it compiles, but it gives me a different error when I run the executable.</p>
  <p>I tried to compile using the following commands:</p>
  <pre><code>g++ -o mycc main.cpp GLSLShader.cpp -lglut -lGLEW -lGL -lm -lglm                 
  </code></pre>
  <p>So let me give you the message and then the actual main.cpp and shader program:</p>
  <h3>Error Message</h3>
  <pre><code>    ^
  main.cpp: At global scope:
  main.cpp:62:7: error: ‘float time’ redeclared as different kind of symbol
  float time = 0;
        ^
  In file included from /usr/include/pthread.h:24:0,
               from /usr/include/x86_64-linux-gnu/c++/4.8/bits/gthr-default.h:35,
               from /usr/include/x86_64-linux-gnu/c++/4.8/bits/gthr.h:148,
               from /usr/include/c++/4.8/ext/atomicity.h:35,
               from /usr/include/c++/4.8/bits/ios_base.h:39,
               from /usr/include/c++/4.8/ios:42,
               from /usr/include/c++/4.8/ostream:38,
               from /usr/include/c++/4.8/iostream:39,
               from main.cpp:3:
  /usr/include/time.h:192:15: error: previous declaration of ‘time_t time(time_t*)’
  extern time_t time (time_t *__timer) __THROW;
            ^
  main.cpp: In function ‘void OnRender()’:
  main.cpp:198:7: error: assignment of function ‘time_t time(time_t*)’
  time = glutGet(GLUT_ELAPSED_TIME)/1000.0f * SPEED;
       ^
  main.cpp:198:7: error: cannot convert ‘float’ to ‘time_t(time_t*)throw () {aka long int(long int*)throw     
  ()}’ in assignment
  main.cpp:213:35: error: cannot convert ‘time_t (*)(time_t*)throw () {aka long int (*)(long int*)throw ()}’ to ‘GLfloat {aka float}’ in argument passing
  glUniform1f(shader(&quot;time&quot;), time);
                                 ^
  </code></pre>
  <h3>main.cpp</h3>
  <pre><code>#include &lt;GL/glew.h&gt;
  #include &lt;GL/freeglut.h&gt;
  #include &lt;iostream&gt;
  
  #include &lt;glm/glm.hpp&gt;
  #include &lt;glm/gtc/matrix_transform.hpp&gt;
  #include &lt;glm/gtc/type_ptr.hpp&gt;
  
  #include &quot;GLSLShader.h&quot;
  
  #define GL_CHECK_ERRORS assert(glGetError()== GL_NO_ERROR);
  
  #ifdef _DEBUG 
  #pragma comment(lib, &quot;glew_static_x86_d.lib&quot;)
  #pragma comment(lib, &quot;freeglut_static_x86_d.lib&quot;)
  #pragma comment(lib, &quot;SOIL_static_x86_d.lib&quot;)
  #else
  #pragma comment(lib, &quot;glew_static_x86.lib&quot;)
  #pragma comment(lib, &quot;freeglut_static_x86.lib&quot;)
  #pragma comment(lib, &quot;SOIL_static_x86.lib&quot;)
  #endif
  
  using namespace std;
  
  //screen size
  const int WIDTH  = 1280;
  const int HEIGHT = 960;
  
  //shader reference
  GLSLShader shader;
  
  //vertex array and vertex buffer object IDs
  GLuint vaoID;
  GLuint vboVerticesID;
  GLuint vboIndicesID;
  
  const int NUM_X = 40; //total quads on X axis
  const int NUM_Z = 40; //total quads on Z axis
  
  const float SIZE_X = 4; //size of plane in world space
  const float SIZE_Z = 4;
  const float HALF_SIZE_X = SIZE_X/2.0f;
  const float HALF_SIZE_Z = SIZE_Z/2.0f;
  
  //ripple displacement speed
  const float SPEED = 2;
  
  //ripple mesh vertices and indices
  glm::vec3 vertices[(NUM_X+1)*(NUM_Z+1)];
  const int TOTAL_INDICES = NUM_X*NUM_Z*2*3;
  GLushort indices[TOTAL_INDICES];
  
  //projection and modelview matrices
  glm::mat4  P = glm::mat4(1);
  glm::mat4 MV = glm::mat4(1);
  
  //camera transformation variables
  int state = 0, oldX=0, oldY=0;
  float rX=25, rY=-40, dist = -7;
  
  //current time
  float time = 0;
  
  //mouse click handler
  void OnMouseDown(int button, int s, int x, int y)
  {
  if (s == GLUT_DOWN)
  {
      oldX = x;
      oldY = y;
  }
  
  if(button == GLUT_MIDDLE_BUTTON)
      state = 0;
  else
      state = 1;
  }
  
  //mosue move handler
  void OnMouseMove(int x, int y)
  {
  if (state == 0)
      dist *= (1 + (y - oldY)/60.0f);
  else
  {
      rY += (x - oldX)/5.0f;
      rX += (y - oldY)/5.0f;
  }
  oldX = x;
  oldY = y;
  
  glutPostRedisplay();
  }
  
  //OpenGL initialization
  void OnInit() {
  //set the polygon mode to render lines
  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  
  GL_CHECK_ERRORS
  //load shader
  shader.LoadFromFile(GL_VERTEX_SHADER, &quot;shaders/shader.vert&quot;);
  shader.LoadFromFile(GL_FRAGMENT_SHADER, &quot;shaders/shader.frag&quot;);
  //compile and link shader
  shader.CreateAndLinkProgram();
  shader.Use();
      //add shader attribute and uniforms
      shader.AddAttribute(&quot;vVertex&quot;);
      shader.AddUniform(&quot;MVP&quot;);
      shader.AddUniform(&quot;time&quot;);
  shader.UnUse();
  
  GL_CHECK_ERRORS
  
  //setup plane geometry
  //setup plane vertices
  int count = 0;
  int i=0, j=0;
  for( j=0;j&lt;=NUM_Z;j++) {
      for( i=0;i&lt;=NUM_X;i++) {
          vertices[count++] = glm::vec3( ((float(i)/(NUM_X-1)) *2-1)* HALF_SIZE_X, 0, ((float(j)/(NUM_Z-1))*2-1)*HALF_SIZE_Z);
      }
  }
  
  //fill plane indices array
  GLushort* id=&amp;indices[0];
  for (i = 0; i &lt; NUM_Z; i++) {
      for (j = 0; j &lt; NUM_X; j++) {
          int i0 = i * (NUM_X+1) + j;
          int i1 = i0 + 1;
          int i2 = i0 + (NUM_X+1);
          int i3 = i2 + 1;
          if ((j+i)%2) {
              *id++ = i0; *id++ = i2; *id++ = i1;
              *id++ = i1; *id++ = i2; *id++ = i3;
          } else {
              *id++ = i0; *id++ = i2; *id++ = i3;
              *id++ = i0; *id++ = i3; *id++ = i1;
          }
      }
  }
  
  GL_CHECK_ERRORS
  
  //setup plane vao and vbo stuff
  glGenVertexArrays(1, &amp;vaoID);
  glGenBuffers(1, &amp;vboVerticesID);
  glGenBuffers(1, &amp;vboIndicesID);
  
  glBindVertexArray(vaoID);
  
      glBindBuffer (GL_ARRAY_BUFFER, vboVerticesID);
      //pass plane vertices to array buffer object
      glBufferData (GL_ARRAY_BUFFER, sizeof(vertices), &amp;vertices[0], GL_STATIC_DRAW);
      GL_CHECK_ERRORS
      //enable vertex attrib array for position
      glEnableVertexAttribArray(shader[&quot;vVertex&quot;]);
      glVertexAttribPointer(shader[&quot;vVertex&quot;], 3, GL_FLOAT, GL_FALSE,0,0);
      GL_CHECK_ERRORS
      //pass the plane indices to element array buffer
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &amp;indices[0], GL_STATIC_DRAW);
      GL_CHECK_ERRORS
            
   cout&lt;&lt;&quot;Initialization successfull&quot;&lt;&lt;endl;
  }
  
  
  //release all allocated resources
  void OnShutdown() {
  //Destroy shader
  shader.DeleteShaderProgram();
  
  //Destroy vao and vbo
  glDeleteBuffers(1, &amp;vboVerticesID);
  glDeleteBuffers(1, &amp;vboIndicesID);
  glDeleteVertexArrays(1, &amp;vaoID);
  
  cout&lt;&lt;&quot;Shutdown successfull&quot;&lt;&lt;endl;
  }
  
  //resize event handler
  void OnResize(int w, int h) {
  //set the viewport size
  glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  //setup the projection matrix
  P = glm::perspective(45.0f, (GLfloat)w/h, 1.f, 1000.f);
  }
  
  //idle event callback
  void OnIdle() {
      glutPostRedisplay();
  }
  
  //display callback 
  void OnRender() {
  //get the elapse time
  time = glutGet(GLUT_ELAPSED_TIME)/1000.0f * SPEED;
  
  //clear the colour and depth buffers
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  
  //set teh camera viewing transformation
  glm::mat4 T     = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
  glm::mat4 Rx    = glm::rotate(T,  rX, glm::vec3(1.0f, 0.0f, 0.0f));
  glm::mat4 MV    = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
  glm::mat4 MVP   = P*MV;
  
  //bind the shader 
  shader.Use();
      //set the shader uniforms
      glUniformMatrix4fv(shader(&quot;MVP&quot;), 1, GL_FALSE, glm::value_ptr(MVP));
      glUniform1f(shader(&quot;time&quot;), time);
          //draw the mesh triangles
          glDrawElements(GL_TRIANGLES, TOTAL_INDICES, GL_UNSIGNED_SHORT, 0);
  
  //unbind the shader
  shader.UnUse();
  
  //swap front and back buffers to show the rendered result
  glutSwapBuffers();
  }
  
  int main(int argc, char** argv) {
  //freeglut initialization calls
  glutInit(&amp;argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  glutInitContextVersion (3, 3);
  glutInitContextFlags (GLUT_CORE_PROFILE | GLUT_DEBUG);
  glutInitWindowSize(WIDTH, HEIGHT);
  glutCreateWindow(&quot;Ripple deformer - OpenGL 3.3&quot;);
      
  //glew initialization   
  glewExperimental = GL_TRUE;
  
  GLenum err = glewInit();
  if (GLEW_OK != err) {
      cerr&lt;&lt;&quot;Error: &quot;&lt;&lt;glewGetErrorString(err)&lt;&lt;endl;
  } else {
      if (GLEW_VERSION_3_3)
      {
          cout&lt;&lt;&quot;Driver supports OpenGL 3.3\nDetails:&quot;&lt;&lt;endl;
      }
  }
  err = glGetError(); //this is to ignore INVALID ENUM error 1282
  GL_CHECK_ERRORS
              
  //print information on screen
  cout&lt;&lt;&quot;\tUsing GLEW &quot;&lt;&lt;glewGetString(GLEW_VERSION)&lt;&lt;endl;
  cout&lt;&lt;&quot;\tVendor: &quot;&lt;&lt;glGetString (GL_VENDOR)&lt;&lt;endl;
  cout&lt;&lt;&quot;\tRenderer: &quot;&lt;&lt;glGetString (GL_RENDERER)&lt;&lt;endl;
  cout&lt;&lt;&quot;\tVersion: &quot;&lt;&lt;glGetString (GL_VERSION)&lt;&lt;endl;
  cout&lt;&lt;&quot;\tGLSL: &quot;&lt;&lt;glGetString (GL_SHADING_LANGUAGE_VERSION)&lt;&lt;endl;
  
  GL_CHECK_ERRORS
  
  //opengl initialization
  OnInit();
  
  //callback hooks
  glutCloseFunc(OnShutdown);
  glutDisplayFunc(OnRender);
  glutReshapeFunc(OnResize);
  glutMouseFunc(OnMouseDown);
  glutMotionFunc(OnMouseMove);
  glutIdleFunc(OnIdle);
  
  //main loop call
  glutMainLoop();
  
  return 0;
  }
  </code></pre>
  <p>And finally the shader code:</p>
  <h3>GLSLShader.cpp</h3>
  <pre><code>#include &quot;GLSLShader.h&quot;
  #include &lt;iostream&gt;
  
  
  GLSLShader::GLSLShader(void)
  {
  _totalShaders=0;
  _shaders[VERTEX_SHADER]=0;
  _shaders[FRAGMENT_SHADER]=0;
  _shaders[GEOMETRY_SHADER]=0;
  _attributeList.clear();
  _uniformLocationList.clear();
  }
  
  GLSLShader::~GLSLShader(void)
  {
  _attributeList.clear(); 
  _uniformLocationList.clear();
  }
  
  void GLSLShader::DeleteShaderProgram() {    
  glDeleteProgram(_program);
  }
  
  void GLSLShader::LoadFromString(GLenum type, const string&amp; source) {    
  GLuint shader = glCreateShader (type);
  
  const char * ptmp = source.c_str();
  glShaderSource (shader, 1, &amp;ptmp, NULL);
  
  //check whether the shader loads fine
  GLint status;
  glCompileShader (shader);
  glGetShaderiv (shader, GL_COMPILE_STATUS, &amp;status);
  if (status == GL_FALSE) {
      GLint infoLogLength;        
      glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &amp;infoLogLength);
      GLchar *infoLog= new GLchar[infoLogLength];
      glGetShaderInfoLog (shader, infoLogLength, NULL, infoLog);
      cerr&lt;&lt;&quot;Compile log: &quot;&lt;&lt;infoLog&lt;&lt;endl;
      delete [] infoLog;
  }
  _shaders[_totalShaders++]=shader;
  }
  
  
  void GLSLShader::CreateAndLinkProgram() {
  _program = glCreateProgram ();
  if (_shaders[VERTEX_SHADER] != 0) {
      glAttachShader (_program, _shaders[VERTEX_SHADER]);
  }
  if (_shaders[FRAGMENT_SHADER] != 0) {
      glAttachShader (_program, _shaders[FRAGMENT_SHADER]);
  }
  if (_shaders[GEOMETRY_SHADER] != 0) {
      glAttachShader (_program, _shaders[GEOMETRY_SHADER]);
  }
  
  //link and check whether the program links fine
  GLint status;
  glLinkProgram (_program);
  glGetProgramiv (_program, GL_LINK_STATUS, &amp;status);
  if (status == GL_FALSE) {
      GLint infoLogLength;
      
      glGetProgramiv (_program, GL_INFO_LOG_LENGTH, &amp;infoLogLength);
      GLchar *infoLog= new GLchar[infoLogLength];
      glGetProgramInfoLog (_program, infoLogLength, NULL, infoLog);
      cerr&lt;&lt;&quot;Link log: &quot;&lt;&lt;infoLog&lt;&lt;endl;
      delete [] infoLog;
  }
  
  glDeleteShader(_shaders[VERTEX_SHADER]);
  glDeleteShader(_shaders[FRAGMENT_SHADER]);
  glDeleteShader(_shaders[GEOMETRY_SHADER]);
  }
  
  void GLSLShader::Use() {
  glUseProgram(_program);
  }
  
  void GLSLShader::UnUse() {
  glUseProgram(0);
  }
  
  void GLSLShader::AddAttribute(const string&amp; attribute) {
  _attributeList[attribute]= glGetAttribLocation(_program, attribute.c_str());    
  }
  
  //An indexer that returns the location of the attribute
  GLuint GLSLShader::operator [](const string&amp; attribute) {
  return _attributeList[attribute];
  }
  
  void GLSLShader::AddUniform(const string&amp; uniform) {
  _uniformLocationList[uniform] = glGetUniformLocation(_program, uniform.c_str());
  }
  
  GLuint GLSLShader::operator()(const string&amp; uniform){
  return _uniformLocationList[uniform];
  }
  
  #include &lt;fstream&gt;
  void GLSLShader::LoadFromFile(GLenum whichShader, const string&amp; filename){
  ifstream fp;
  fp.open(filename.c_str(), ios_base::in);
  if(fp) {         
      string line, buffer;
      while(getline(fp, line)) {
          buffer.append(line);
          buffer.append(&quot;\r\n&quot;);
      }        
      //copy to source
      LoadFromString(whichShader, buffer);        
  } else {
      cerr&lt;&lt;&quot;Error loading shader: &quot;&lt;&lt;filename&lt;&lt;endl;
  }
  }
  </code></pre>
  <h3>Debug 1 [<strong>RESOLVED</strong>]</h3>
  <p>Ahh, so I did what @KimKulling suggested and made the variable into <code>elapsedTime</code> instead of just <code>time</code>. So the file does compile to an executable <code>mycc</code>, but when I run it I get the following error:</p>
  <pre><code>Inconsistency detected by ld.so: dl-version.c: 224: _dl_check_map_versions: Assertion `needed != ((void *)0)' failed!
  </code></pre>
  <p>The line that it points to: 224 is just the first line of the main function <code>int main() . . .</code>.</p>
  <p>I worked on it some more and discovered this issue has to do with an existing bug associated with dynamic library inconsistencies with OpenGL/C++. There is an existing bug filed on this issue.</p>
  <p><a href="https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642" rel="nofollow noreferrer">https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642</a></p>
  <p>The good news is that someone found a workaround.</p>
  <p><a href="https://stackoverflow.com/questions/20007961/error-running-a-compiled-c-file-uses-opengl-error-inconsistency-detected">error running a compiled C++ file (uses OpenGL). Error: “Inconsistency detected by ld.so: dl-version.c: 224”</a></p>
  <p>All I had to do was use different compile settings. It was really not intuitive.</p>
  <p>I had to add a directory link to the video driver. Here is what worked:</p>
  <pre><code> g++ -L/usr/lib/nvidia-340/ main.cpp GLSLShader.cpp -lglut -lGLEW -lGL 
  </code></pre>