I wanted to understand how the OpenGL loader library glbinding works, but I couldn't compile my very basic example, which is a reduced version of their cubescape example:
#include <iostream>
#include <GLFW/glfw3.h>
#include <glbinding/glbinding.h>
#include <glbinding-aux/ContextInfo.h>
using std::cout;
using std::endl;
int main()
{
  if (glfwInit())
  {
    // ------ create window
    auto const windowPtr = glfwCreateWindow(640, 480, "tc0001", nullptr, nullptr);
    if (windowPtr)
    {
      glfwHideWindow(windowPtr);
      glfwMakeContextCurrent(windowPtr);
      glbinding::initialize(glfwGetProcAddress, false);
      cout << "OpenGL Version:  " << glbinding::aux::ContextInfo::version() << endl;
      cout << "OpenGL Vendor:   " << glbinding::aux::ContextInfo::vendor() << endl;
      cout << "OpenGL Renderer: " << glbinding::aux::ContextInfo::renderer() << endl;
      // ------ destroy window
      glfwDestroyWindow(windowPtr);
    }
    else
    {
      cout << "glfwCreateWindow error" << endl;
    }
    glfwTerminate();
  }
  else
  {
    cout << "glfwInit error" << endl;
  }
}
The culprit is the line:
cout << "OpenGL Version:  " << glbinding::aux::ContextInfo::version() << endl;
The compiler complains about this line, and after that, as usual, outputs a lot of information about failed attempts to find a right implementation of the ‘operator<<’:
error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘glbinding::Version’)
What am I doing wrong?
- OS: Ubuntu 22.04.3 LTS
 - Compiler: g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
 - glbinding: 3.3.0
 
                        
The
version()method returns an object of typeglbinding::Versionwhich cannot be automatically converted to a string. You need to usetoString():cout << "OpenGL Version: " << glbinding::aux::ContextInfo::version() << endl;