Reputation:
While reading the OpenGL 4 Shading Language Cookbook, I encountered the OpenGL Loader Gen library and immediately wanted to try it out. I started creating a small example program that you can see underneath.
#include "GLFW/glfw3.h"
#include "GL/gl_core_4_1.hpp"
namespace engine
{
class Window
{
private:
const unsigned int width;
const unsigned int height;
const char *title;
const void refresh()
{
glfwSwapBuffers(this -> glfwWindow);
glfwPollEvents();
}
protected:
GLFWwindow *glfwWindow;
public:
Window(const unsigned int width, const unsigned int height, const char title[]): width(width), height(height), title(title)
{
if (glfwInit() != GLFW_TRUE)
{
throw "Couldn't initialise the required GLFW library.";
}
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
if (this -> glfwWindow)
{
throw "Cannot create a secondary window.";
}
this -> glfwWindow = glfwCreateWindow(this -> width, this -> height, this -> title, NULL, NULL);
// This is the crucial line that will stop the program from compiling.
gl::exts::LoadTest context = gl::sys::LoadFunctions();
if (!context)
{
throw "Couldn't initialse the required GL library.";
}
glfwMakeContextCurrent(this -> glfwWindow);
glfwSwapInterval(GLFW_TRUE);
if (!glfwWindow)
{
glfwTerminate();
throw "Couldn't create a new initially empty window.";
}
}
const bool await()
{
this -> refresh();
if (glfwWindowShouldClose(this -> glfwWindow))
{
glfwDestroyWindow(this -> glfwWindow);
glfwTerminate();
return false;
}
return true;
}
};
}
int main(const int argc, const char *argv[])
{
engine::Window window(1280, 720, "Foundation");
while (window.await())
{
}
return 0x00000000;
}
My next step was to try compiling the program with the LLVM
compiler on computer running on the macOS High Sierra operating system.
clang++ -o Application.exec Subdirectory/*.cpp -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
However, during compilation I receive the following unexpected linker error:
Undefined symbols for architecture x86_64:
"gl::sys::LoadFunctions()", referenced from:
engine::Window::Window(unsigned int, unsigned int, char const*) in Application-58a670.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is my actual question: how do I let the program shown above compile using the previously mentioned OpenGL Loader Gen library?
Upvotes: 1
Views: 278
Reputation: 2192
from the docs
The above command line will generate gl_core_3_3.h and gl_core_3_3.c files. Simply include them in your project; there is no library to build, no unresolved externals to filter through.
You need to run their generator to produce those source files.
Upvotes: 2